88 lines
3.3 KiB
C#
88 lines
3.3 KiB
C#
using EnVisage.Code.BLL;
|
|
using EnVisage.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.Script.Serialization;
|
|
|
|
namespace EnVisage.Controllers
|
|
{
|
|
public class NotificationController : BaseController
|
|
{
|
|
// GET: Notification
|
|
public ActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public JsonResult Edit(NotificationModel data)
|
|
{
|
|
if (HttpContext.User.Identity.IsAuthenticated && HttpContext.User.Identity.GetID() != Guid.Empty.ToString())
|
|
{
|
|
NotificationManager nm = new NotificationManager(null);
|
|
nm.UpdateNotificationAsViewed(data);
|
|
}
|
|
|
|
return ActiveNotifications();
|
|
|
|
}
|
|
public ActionResult PassThruLink(Guid Id)
|
|
{
|
|
//"?ptab=Details";
|
|
NotificationManager nm = new NotificationManager(null);
|
|
var notification=nm.Load(Id, true);
|
|
if (notification != null)
|
|
{
|
|
NotificationModel model = new NotificationModel(notification,this.DbContext);
|
|
nm.UpdateNotificationAsViewed(model);
|
|
var id = notification.IdinLink;
|
|
bool goToDetailsTab = false;
|
|
if (notification.Link != null)
|
|
{
|
|
if (notification.Link.ToLower().EndsWith("details"))
|
|
goToDetailsTab = true;
|
|
}
|
|
if (this.DbContext.Projects.Any(x => x.Id == id))
|
|
return RedirectToAction("Edit", "Project", new { Id = id });
|
|
if (this.DbContext.Scenarios.Any(x => x.Id == id))
|
|
if (goToDetailsTab)
|
|
return RedirectToAction("Details", "Scenarios", new { Id = id, ptab = "Details" });
|
|
else
|
|
return RedirectToAction("Details", "Scenarios", new { Id = id });
|
|
|
|
}
|
|
return RedirectToAction("Index", "Home");
|
|
|
|
}
|
|
public JsonResult ActiveNotifications()
|
|
{
|
|
if (HttpContext.User.Identity.IsAuthenticated && HttpContext.User.Identity.GetID() != Guid.Empty.ToString())
|
|
{
|
|
NotificationManager nm = new NotificationManager(null);
|
|
Guid userID = Guid.Parse(HttpContext.User.Identity.GetID());
|
|
Dictionary<Guid, List<Notification>> list = nm.GetNotifications(userID);
|
|
List<NotificationModel> notifications = new List<NotificationModel>();
|
|
foreach (Guid key in list.Keys)
|
|
{
|
|
foreach (Notification n in list[key])
|
|
{
|
|
NotificationModel model = new NotificationModel(n,this.DbContext);
|
|
if (model.ExpiresOnDate.HasValue && (model.ExpiresOnDate.Value - DateTime.Now).TotalDays <= 0)
|
|
nm.UpdateNotificationAsViewed(model);
|
|
else
|
|
notifications.Add(model);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//var output = Newtonsoft.Json.JsonConvert.SerializeObject(notifications);
|
|
return Json(notifications, JsonRequestBehavior.AllowGet);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
} |