public IHttpActionResult Update(NotificationBindingModel nbm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var notification = Mapper.Map <NotificationBindingModel, Notification>(nbm);

                    _notificationService.Update(notification);

                    notification = _notificationService.GetById(notification.Id);

                    var nbmUp = Mapper.Map <Notification, NotificationBindingModel>(notification);
                    return(Ok(nbmUp));
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
            return(Ok(StatusCode(HttpStatusCode.BadRequest)));
        }
        public IHttpActionResult Delete(Guid id)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var nbm = new NotificationBindingModel
                    {
                        Id = id
                    };
                    var notification = Mapper.Map <NotificationBindingModel, Notification>(nbm);
                    _notificationService.Delete(notification.Id);

                    return(Ok());
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
            return(Ok(StatusCode(HttpStatusCode.BadRequest)));
        }
コード例 #3
0
        public ActionResult Index(NotificationBindingModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                model.TargetAudience = 2; //Users Only

                var apiResponse = AsyncHelpers.RunSync <JObject>(() => ApiCall.CallApi("api/Admin/AddNotification", User, model));

                if (apiResponse == null || apiResponse is Error)
                {
                    return(new HttpStatusCodeResult(500, "Internal Server Error"));
                }
                else
                {
                    TempData["SuccessMessage"] = "The notification has been sent successfully.";
                    model.SetSharedData(User);
                    return(Json("Success"));
                }
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(Utility.LogError(ex)));
            }
        }
コード例 #4
0
        public async Task <ActionResult> SendNotification(NotificationBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                var errorList = ModelState.Values.SelectMany(m => m.Errors)
                                .Select(e => e.ErrorMessage)
                                .ToList();

                return(new HttpStatusCodeResult(400, string.Join("\n", errorList)));
            }

            NotificationType type = (NotificationType)model.NotificationType;

            var notification = new Notification()
            {
                Content = model.Content,
                Type    = type,
                SendOn  = DateTime.Now
            };

            var template = System.IO.File.ReadAllText(Path.Combine(
                                                          AppDomain.CurrentDomain.BaseDirectory,
                                                          @"Views\RazorEngine\_PagedNotificationViewModel.cshtml"));
            var renderedPartialView = Razor.Parse(template,
                                                  Mapper.Map <Notification, PagedNotificationViewModel>(notification));

            var hubContext = GlobalHost.ConnectionManager.GetHubContext <NotificationsHub>();

            hubContext.Clients.All.receiveNotification(renderedPartialView);

            hubContext.Clients.All.receiveNotificationCount();

            var allUsers = this.Data.Users.All();

            foreach (var user in allUsers)
            {
                var n = new Notification()
                {
                    Content = model.Content,
                    Type    = type,
                    SendOn  = DateTime.Now,
                    User    = user
                };

                user.Notifications.Add(n);
            }

            this.Data.SaveChanges();

            return(new HttpStatusCodeResult(200, "Notification sent succssesfully."));
        }
コード例 #5
0
 public AddNotificationsViewModel()
 {
     TargetOptions = new SelectList(new List <SelectListItem>());
     Notification  = new NotificationBindingModel();
 }