Exemple #1
0
        public ActionResult SendNotification(NotificationVM vm)
        {
            if (ModelState.IsValid)
            {
                var user = UserManager.FindByEmail(vm.Email);
                if (user != null)
                {
                    user = db.Users.FirstOrDefault(u => u.Id == user.Id);
                }

                if (user == null)
                {
                    ModelState.AddModelError("Email", "The Email is incorrect");
                    return(View(vm));
                }
                user.Notifications.Add(new Notification()
                {
                    Title      = vm.Title,
                    Content    = vm.Content,
                    SenderName = User.Identity.Name,
                    User       = user
                });

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(vm));
        }
        public async Task <IActionResult> SendNotification(NotificationVM vm)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(vm.Email);

                if (user == null)
                {
                    ModelState.AddModelError("Email", "The Email provided is incorrect");
                    return(View(vm));
                }

                user.Notifications.Add(new Notification()
                {
                    Title   = vm.Title,
                    Content = vm.Content,
                    User    = user
                });

                await _dbContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(vm));
        }
Exemple #3
0
        public bool send(string title, string message, DialogMode mode = DialogMode.Notification)
        {
            switch (mode)
            {
            case DialogMode.Confirmation:
                //Notification.
                ConfirmationVM _confirmation = new ConfirmationVM(title, message);
                if (ContainerStore.Singleton.windows.showDialog <ConfirmationVM>(_confirmation).Value)
                {
                    return(true);
                }
                break;

            case DialogMode.GetInput:
                //Notification.
                GetInputVM _getInput = new GetInputVM(title, message);
                if (ContainerStore.Singleton.windows.showDialog <GetInputVM>(_getInput).Value)
                {
                    return(true);
                }
                break;

            case DialogMode.Notification:
                //Notification.
                NotificationVM _notification = new NotificationVM(title, message);
                if (ContainerStore.Singleton.windows.showDialog <NotificationVM>(InputViewModel: _notification).Value)
                {
                    return(true);
                }
                break;
            }
            return(false);
        }
Exemple #4
0
        /// <summary>
        /// 获取单条消息通知
        /// </summary>
        /// <param name="receiver"></param>
        /// <returns></returns>
        public NotificationVM GetNotification(ApplicationUser receiver)
        {
            var notification = _notification
                               .GetAllIncluding(x => x.Receiver)
                               .FirstOrDefault(x => x.Receiver == receiver);
            var notificationVM = new NotificationVM(notification);

            return(notificationVM);
        }
Exemple #5
0
        public HttpResponseMessage NotifyManager(NotificationVM n)
        {
            NotificationVM notification = BusinessLogic.NotificationBL.NotifyManager(n);

            if (notification == null)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, notification));
        }
Exemple #6
0
        public HttpResponseMessage NotifySupervisor(NotificationVM n)
        {
            NotificationVM notification = BusinessLogic.NotificationBL.NotifySupervisor(n);

            if (notification == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, notification));
        }
Exemple #7
0
        public JsonResult UpdateNotification(NotificationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(null));
                }
                else
                {
                    //var NotificationExist = UnitOfWork.NotificationSettingBL.CheckExist(b => b.ReservationStatusId == model.ReservationStatusId && b.ActionStep == model.ActionStep&&b. );
                    //if (NotificationExist)
                    //{
                    //    return Json(new { success = false, Message = "Notification setting already exists" });
                    //}
                    var Notification = UnitOfWork.NotificationSettingBL.GetNotificationWithDetails(f => f.Id == model.Id);
                    if (Notification != null)
                    {
                        Notification.ReservationStatusId = model.ReservationStatusId;
                        Notification.ActionStep          = model.ActionStep;
                        if (model.IsDisable == null)
                        {
                            Notification.IsDisabled = true;
                        }
                        else
                        {
                            Notification.IsDisabled = model.IsDisable;
                        }
                        Notification.LnkNotificationJobTitle = model.JobTitleId.Where(r => r.HasValue).Select(r => new LnkNotificationJobTitle
                        {
                            JobTitleId = r.Value
                        }).ToHashSet();

                        UnitOfWork.NotificationSettingBL.Update(Notification);
                        if (UnitOfWork.Complete() > 0)
                        {
                            return(Json(new { success = true, Message = "Notification setting updated successfully" }));
                        }
                        else
                        {
                            return(Json(new { success = false, Message = "Failed to update Notification setting" }));
                        }
                    }
                    else
                    {
                        return(Json(new { success = false, Message = "Notification setting not found" }));
                    }
                }
            }
            catch (Exception e)
            {
                return(Json(new { success = false, Message = "An error occured , please try again later" }));
            }
        }
Exemple #8
0
        public static List <NotificationVM> GetNotifications(this Members _members, List <Tasks> tasks, List <ProjectMembers> projectMembers, List <Calendar> calendars)
        {
            List <NotificationVM> _GetNotifications = new List <NotificationVM>();
            var _tasks = tasks
                         .Where(n => n.EmployeeGUID == _members.EmployeeGUID)
                         .Select(n => new { n.TaskName, n.AssignedDate, n.IsRead, n.EmployeeGUID, n.Project.ProjectName, n.ProjectGUID, n.Project.Employee1.EmployeeName });
            var _projectMember = projectMembers
                                 .Where(n => n.EmployeeGUID == _members.EmployeeGUID)
                                 .Select(n => new { n.ProjectGUID, n.Project.ProjectName, n.Project.Employee1.EmployeeName, n.IsRead, n.InvideDate });
            var _calendars = calendars
                             .Where(n => n.Members.EmployeeGUID == _members.EmployeeGUID && n.CategoryID == 2)
                             .Select(n => new { n.Subject, n.IsRead, n.Start, n.CreateDate });

            foreach (var t in _tasks)
            {
                NotificationVM vm = new NotificationVM();
                vm.TaskName         = t.TaskName;
                vm.Category         = "Task";
                vm.ProjectName      = t.ProjectName;
                vm.ProjectGUID      = (Guid)t.ProjectGUID;
                vm.NotificationDate = (DateTime)t.AssignedDate;
                vm.EmployeeName     = _members.Employee.EmployeeName;
                vm.EmployeeGUID     = (Guid)_members.EmployeeGUID;
                vm.MangerName       = t.EmployeeName;
                vm.IsRead           = (bool)t.IsRead;
                _GetNotifications.Add(vm);
            }
            foreach (var pb in _projectMember)
            {
                NotificationVM vm = new NotificationVM();
                vm.NotificationDate = (DateTime)pb.InvideDate;
                vm.Category         = "InvideProject";
                vm.ProjectName      = pb.ProjectName;
                vm.ProjectGUID      = pb.ProjectGUID;
                vm.MangerName       = pb.EmployeeName;
                vm.EmployeeName     = _members.Employee.EmployeeName;
                vm.EmployeeGUID     = (Guid)_members.EmployeeGUID;
                vm.IsRead           = (bool)pb.IsRead;
                _GetNotifications.Add(vm);
            }
            foreach (var c in _calendars)
            {
                NotificationVM vm = new NotificationVM();
                vm.NotificationDate = (DateTime)c.CreateDate;
                vm.Category         = "Calendar";
                vm.CalendarDate     = c.Start;
                vm.CalendarName     = c.Subject;
                vm.EmployeeName     = _members.Employee.EmployeeName;
                vm.EmployeeGUID     = (Guid)_members.EmployeeGUID;
                vm.IsRead           = (bool)c.IsRead;
                _GetNotifications.Add(vm);
            }
            return(_GetNotifications);
        }
Exemple #9
0
        public JsonResult CreateNotification(NotificationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(null));
                }
                else
                {
                    var NotificationExist = UnitOfWork.NotificationSettingBL.CheckExist(b => b.ReservationStatusId == model.ReservationStatusId && b.ActionStep == model.ActionStep);
                    if (NotificationExist)
                    {
                        return(Json(new { success = false, Message = "Notification setting already exists" }));
                    }


                    var Notification = new NotificationSetting
                    {
                        ReservationStatusId = model.ReservationStatusId,
                        ActionStep          = model.ActionStep,
                    };
                    if (model.IsDisable == null)
                    {
                        Notification.IsDisabled = true;
                    }
                    else
                    {
                        Notification.IsDisabled = model.IsDisable;
                    }


                    Notification.LnkNotificationJobTitle = model.JobTitleId.Where(r => r.HasValue).Select(r => new LnkNotificationJobTitle
                    {
                        JobTitleId = r.GetValueOrDefault()
                    }).ToList();

                    UnitOfWork.NotificationSettingBL.Add(Notification);
                    if (UnitOfWork.Complete() > 0)
                    {
                        return(Json(new { success = true, Message = "Notification setting added successfully" }));
                    }
                    else
                    {
                        return(Json(new { success = false, Message = "Failed to add notification setting" }));
                    }
                }
            }
            catch (Exception)
            {
                return(Json(new { success = false, Message = "An error occured , please try again later" }));
            }
        }
Exemple #10
0
 public Task <int> InsertAsync(NotificationVM entity)
 {
     return(Task.Run <int>(() =>
     {
         var dbEntity = Mapper.Map <NotificationVM, Notification>(entity);
         dbEntity.AddedOn = DateTime.Now;
         dbEntity.Active = true;
         dbEntity.Position = 1;
         var returnedObject = _NotificationRepo.Add(dbEntity);
         return returnedObject.ID;
     }));
 }
Exemple #11
0
        public async Task <JsonResult> Notifications()
        {
            var list = await _context.Notifications.Where(n => n.MarkAsRead == false).ToListAsync();

            var ns = new NotificationVM
            {
                Count         = list.Count,
                Notifications = list
            };

            return(Json(ns));
        }
        public void CadastrarNotificacao(NotificationVM objeto)
        {
            var NotificationEntity = new NotificationEntity {
                DescricaoNotificacao = objeto.DescricaoNotificacao,
                IdUsuario            = objeto.IdUsuario,
                IsConcluida          = objeto.IsConcluida,
                LevelNotification    = objeto.LevelNotification,
                TipoNotificacao      = objeto.TipoNotificacao
            };

            _repositoryNotification.Salvar(NotificationEntity);
            _repositoryNotification.Context.SaveChanges();
        }
Exemple #13
0
        /// <summary>
        /// 管理员获取所有的消息通知
        /// </summary>
        /// <returns></returns>
        public List <NotificationVM> AdminGetNotifications()
        {
            var notificationsVM = new List <NotificationVM>();
            var notifications   = _notification
                                  .GetAllIncluding(x => x.Receiver)
                                  .OrderByDescending(x => x.AddTime).ToList();

            foreach (var notification in notifications)
            {
                var notificationVM = new NotificationVM(notification);
                notificationVM.OrderNumber = (notificationsVM.Count() + 1).ToString();
                notificationsVM.Add(notificationVM);
            }
            return(notificationsVM);
        }
Exemple #14
0
        public async Task <IActionResult> AddNotification([FromBody] NotificationVM vm)
        {
            if (!ModelState.IsValid)
            {
                string errorMsg = null;
                foreach (var m in ModelState.Values)
                {
                    foreach (var msg in m.Errors)
                    {
                        errorMsg = msg.ErrorMessage;
                    }
                }
                return(BadRequest(errorMsg));
            }

            var user = await _userManager.FindByIdAsync(User.Identity.Name);

            if (user == null)
            {
                return(NotFound());
            }

            Notification newNotification = new Notification
            {
                VideoCommentId      = vm.VideoCommentId,
                VideoCommentReplyId = vm.VideoCommentReplyId,
                VideoPostId         = vm.VideoPostId,
                YouTubeVideoId      = vm.YouTubeVideoId,
                IsGoogleDriveVideo  = vm.IsGoogleDriveVideo,
                UserId      = vm.UserId,
                NickName    = user.NickName,
                Comment     = vm.Comment,
                DateCreated = DateTime.Now
            };

            await _nRepository.AddAsync(newNotification);

            await _nRepository.CommitAsync();

            var notificationVM = Mapper.Map <Notification, NotificationVM>(newNotification);

            return(CreatedAtRoute("GetNotification", new
            {
                controller = "CardDetail",
                id = newNotification.NotificationId
            }, null));
        }
Exemple #15
0
 // mark one notification as read
 public static bool MarkOneAsRead(NotificationVM n)
 {
     using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext())
     {
         try
         {
             Notification n_orig = entities.Notifications.ToList().Find(x => x.NotificationId == n.NotificationId);
             n_orig.IsRead = true;
             entities.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
Exemple #16
0
        public async Task SendNotiAsync(int permissionId, NotificationCM model)
        {
            List <string> connections = new List <string>();
            //try
            //{
            //    var permission = _permissionService.GetPermission(permissionId);
            //    if (permission == null)
            //    {
            //        return;
            //    }

            //    var userIds = _permissionService.GetUsersByPermission(permissionId);

            //    foreach (var userId in userIds)
            //    {
            //        try
            //        {
            //            var notification = CreateNotification(userId, model);
            //            _notiService.CreateNotification(notification);
            //            _notiService.SaveNotification();

            //            connections = connections.Union(_hubService.GetHubUserConnections(_ => _.UserId.Equals(userId))
            //                            .Select(_ => _.Connection).ToList()).ToList();
            //        }
            //        catch { continue; }
            //    }
            //}
            //catch (Exception e)
            //{
            //    throw;
            //}

            //Send notification
            var _notification = new NotificationVM
            {
                Title       = model.Title,
                Type        = model.Type,
                Body        = model.Body,
                NData       = model.NData == null ? null : JsonConvert.SerializeObject(model.NData),
                IsSeen      = false,
                DateCreated = DateTime.Now
            };

            _hubContext.Clients.Clients(connections)
            .SendAsync("Notify", JsonConvert.SerializeObject(_notification.Adapt <NotificationVM>()));
        }
Exemple #17
0
        //AddAcptNotification with repId
        public static bool AdjApprNotification(int fromEmpId, int toEmpId, NotificationVM n)
        {
            NotificationVM adjApprNoti = new NotificationVM();

            using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext())
            {
                try
                {
                    Notification noti = new Notification();
                    noti.FromEmp = fromEmpId;
                    noti.ToEmp   = toEmpId;
                    noti.NotificationDateTime = System.DateTime.Now;
                    noti.RouteUri             = "";
                    noti.Type    = "Adjustment Submitted";
                    noti.Content = "Missing Stock";
                    noti.IsRead  = true;
                    entities.Notifications.Add(noti);
                    int rowinserted = entities.SaveChanges();
                    if (rowinserted > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                //adjApprNoti = entities.Notifications.Select(r => new NotificationVM()
                //{
                //    FromEmp = fromEmpId,
                //    ToEmp = toEmpId,
                //    NotificationId = n.NotificationId,
                //    NotificationDateTime = n.NotificationDateTime,
                //    RouteUri = n.RouteUri,
                //    Type = n.Type,
                //    Content = n.Content,
                //    IsRead = n.IsRead

                //}).First<NotificationVM>();
            }
        }
Exemple #18
0
        public ActionResult <Notification> GetNotification(Guid ID)
        {
            try
            {
                var rs = _notificationService.GetByID(ID);
                if (rs == null)
                {
                    return(NotFound("ID not found!"));
                }

                NotificationVM result = _mapper.Map <NotificationVM>(rs);
                return(Ok(result));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public int AtualizarNotificacao(NotificationVM objeto)
        {
            var notificacaoEntity = _repositoryNotification.Selecionar(o => o.Id == objeto.Id);

            notificacaoEntity = new NotificationEntity
            {
                Id = objeto.Id,
                DescricaoNotificacao = objeto.DescricaoNotificacao,
                IdUsuario            = objeto.IdUsuario,
                IsConcluida          = objeto.IsConcluida,
                LevelNotification    = objeto.LevelNotification,
                TipoNotificacao      = objeto.TipoNotificacao
            };

            _repositoryNotification.Update(notificacaoEntity);
            _repositoryNotification.Context.SaveChanges();
            return((int)RestResponse.SUCCESS);
        }
Exemple #20
0
 public Task <bool> UpdateAsync(NotificationVM entity)
 {
     return(Task.Run <bool>(async() =>
     {
         var dbEntity = await getById(entity.ID);
         if (dbEntity != null)
         {
             var mappedEntity = Mapper.Map(entity, dbEntity);
             mappedEntity.UpdatedOn = DateTime.Now;
             _NotificationRepo.Update(mappedEntity, mappedEntity.ID);
             return true;
         }
         else
         {
             return false;
         }
     }));
 }
Exemple #21
0
        //Notification NotifySupervisor with notfication
        public static NotificationVM NotifySupervisor(NotificationVM nn)
        {
            NotificationVM notiSupervisor = new NotificationVM();

            using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext())
            {
                notiSupervisor = entities.Notifications.Where(n => n.Employee.Role == "Store Supervisor").Select(n => new NotificationVM()
                {
                    NotificationId       = n.NotificationId,
                    NotificationDateTime = n.NotificationDateTime,
                    FromEmp  = n.FromEmp,
                    ToEmp    = n.ToEmp,
                    RouteUri = n.RouteUri,
                    Type     = n.Type,
                    Content  = n.Content,
                    IsRead   = n.IsRead
                }).First <NotificationVM>();
            }
            return(notiSupervisor);
        }
Exemple #22
0
        public IActionResult SendNotifications([Bind("Name,Description,Link")] NotificationVM boVM)
        {
            if (string.IsNullOrEmpty(boVM.Name))
            {
                return(Json(new { result = false, message = "发送失败,消息名称不允许为空!" }));
            }
            if (string.IsNullOrEmpty(boVM.Description))
            {
                return(Json(new { result = false, message = "发送失败,消息内容不允许为空!" }));
            }
            var users = _userManager.Users;

            if (users.Count() > 0)
            {
                var sendCount = 0;
                var link      = string.IsNullOrEmpty(boVM.Link) ? "javascript:" : boVM.Link;

                foreach (var user in users)
                {
                    var notification = new Notification
                    {
                        Receiver           = user,
                        Name               = boVM.Name.Replace(" ", ""),
                        Description        = boVM.Description.Replace(" ", ""),
                        Link               = link.Replace(" ", ""),
                        IsAbnormal         = false,
                        IsRead             = false,
                        NotificationSource = NotificationSourceEnum.AppUser
                    };
                    AppNotification.SendNotification(notification);
                    sendCount++;
                }
                if (sendCount > 0 && sendCount < users.Count())
                {
                    var sendFail = users.Count() - sendCount;
                    return(Json(new { result = false, message = "成功发送[ " + sendCount + "条 ],失败[ " + sendFail + "条 ]" }));
                }
                return(Json(new { result = true, message = "全部发送成功!" }));
            }
            return(Json(new { result = false, message = "全部发送失败!" }));
        }
        private List <NotificationVM> EntityToVMNotification(List <NotificationEntity> objeto)
        {
            var listNotification = new List <NotificationVM>();
            var notificationVM   = new NotificationVM();

            #region Iteração
            foreach (var item in objeto)
            {
                notificationVM.DescricaoNotificacao = item.DescricaoNotificacao;
                notificationVM.IdUsuario            = item.IdUsuario;
                notificationVM.IsConcluida          = item.IsConcluida;
                notificationVM.LevelNotification    = item.LevelNotification;
                notificationVM.TipoNotificacao      = item.TipoNotificacao;
                notificationVM.Id = item.Id;
                listNotification.Add(notificationVM);
                notificationVM = new NotificationVM();
            }
            #endregion

            return(listNotification.OrderByDescending(o => o.Id).ToList());
        }
        public ActionResult Delete(int id)
        {
            var notif = new NotificationVM();

            try
            {
                var res = resumeService.DeleteResume(User.Identity.Name, id);
                notif.Message = "Success";
                notif.Type    = NotificationType.Success;
            }
            catch (Exception ex)
            {
                logger.Log(LogType.Error, "Resume delete failed.", ex);
                notif.Message = "Failed to delete";
                notif.Type    = NotificationType.Error;
            }

            var vm = new ResumeListVM(resumeService.GetAllForUser(User.Identity.Name));

            vm.Notification = notif;
            return(PartialView("~/Views/Resume/ResumeListPartial.cshtml", vm));
        }
        public ActionResult _NotificationSection()
        {
            var model = new NotificationVM();

            model.SingleNotification = (from n in db.Notifications
                                        where n.isRead == false
                                        orderby n.CreatedDate descending
                                        select new SingleNotificationVM
            {
                Id = n.Id,
                IsPrescriptionNotification = n.IsPrescriptionNotification,
                PrescriptionLink = n.PrescriptionLink,
                Message = n.Message,
                CreatedDate = n.CreatedDate,
                isRead = n.isRead,
                Icon = n.Icon,
                BackgroundColorIcon = n.BackgroundColorIcon
            }).ToList().Take(5);

            //model.NumberOfUnreadNotifications = db.Notifications
            //    .Where(n => n.isRead == false).Count();

            model.NumberOfUnreadNotifications = model.SingleNotification.Count();

            ViewBag.PresLink = "#";

            if (model.SingleNotification.Any(n => n.IsPrescriptionNotification == true))
            {
                foreach (var item in model.SingleNotification)
                {
                    if (item.IsPrescriptionNotification == true)
                    {
                        ViewBag.PresLink = item.PrescriptionLink;
                    }
                }
            }

            return(PartialView(model));
        }
 // GET: Admin/Notifications
 public ActionResult Index(int PageNo = 1, int PageSize = 10, string SearchTerm = "")
 {
     try
     {
         string            query    = "PageNo=" + PageNo + "&PageSize=" + PageSize + "&SearchTerm=" + SearchTerm;
         NotificationAPIVM apiModel = objAPI.GetRecordByQueryString <NotificationAPIVM>("configuration", "notification", query);
         NotificationVM    model    = new NotificationVM();
         model.Notificationlist = apiModel.Notification;
         model.PagingInfo       = new PagingInfo {
             CurrentPage = PageNo, ItemsPerPage = PageSize, TotalItems = apiModel.TotalRecords
         };
         if (Request.IsAjaxRequest())
         {
             return(PartialView("_pvNotificationsList", model));
         }
         return(View(model));
     }
     catch (AuthorizationException)
     {
         TempData["ErrMsg"] = "Your Login Session has expired. Please Login Again";
         return(RedirectToAction("Login", "Account", new { Area = "" }));
     }
 }
        public async Task <HttpResponseMessage> edit([FromBody] NotificationVM entity)
        {
            var state = await _typeService.UpdateAsync(entity);

            return(Request.CreateResponse(HttpStatusCode.OK, state, Configuration.Formatters.JsonFormatter));
        }
Exemple #28
0
        public HttpResponseMessage AdjApprNotification(string fromEmpId, string toEmpId, NotificationVM n)
        {
            int FromEmpId = Convert.ToInt16(fromEmpId);
            int ToEmpId   = Convert.ToInt16(toEmpId);

            try
            {
                BusinessLogic.NotificationBL.AdjApprNotification(FromEmpId, ToEmpId, n);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message));
            }
        }
 public List <NotificationVM> Get([FromQuery] NotificationVM objeto)
 {
     return(_notificationBll.ListarNotificacoesPorUsuarioLogado((int)objeto.IdUsuario));
 }
 public int Post([FromBody] NotificationVM objeto)
 {
     return(_notificationBll.AtualizarNotificacao(objeto));
 }