Пример #1
0
        public virtual ActionResult Edit(string EventName, Guid id)
        {
            try
            {
                e  = GetEvent(EventName);
                pn = e.PushNotifications.Where(x => x.Id == id).First();
            }
            catch (Exception)
            {
                throw new HttpException(404, "Push Notification not found");
            }

            var model = new EditPushNotificationModel()
            {
                Id       = pn.Id,
                EventId  = e.Id,
                Message  = pn.Message,
                SendDate = new ModelTime {
                    Date = pn.SendDate
                },
                PlaySound = pn.PlaySound
            };

            return(PartialView(MVC.PushNotification.Views.Edit, model));
        }
Пример #2
0
        public virtual ActionResult Add(Guid eventId)
        {
            e = GetEvent(eventId);
            var model = new EditPushNotificationModel
            {
                EventId         = eventId,
                SendImmediately = true,
                SendDate        = new ModelTime {
                    Date = e.NowLocal
                }
            };

            return(PartialView(MVC.PushNotification.Views.Edit, model));
        }
Пример #3
0
        public virtual ActionResult Save(EditPushNotificationModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    e = GetEvent(model.EventId);

                    if (model.Id == Guid.Empty)
                    {
                        pn = e.AddPushNotification((model.SendImmediately) ? e.NowLocal : model.SendDate.FullDate,
                                                   model.Message,
                                                   model.PlaySound);
                    }
                    else
                    {
                        pn = e.PushNotifications.Where(x => x.Id == model.Id).First();
                        if (pn.Sent)
                        {
                            throw new Exception("Can't edit Push Notifications already sent");
                        }

                        pn.SendDate  = (model.SendImmediately) ? e.NowLocal : model.SendDate.FullDate;
                        pn.Message   = model.Message;
                        pn.PlaySound = model.PlaySound;
                        pn.ConvertAllToUTC();
                    }
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }

            return(ModelState.IsValid ?
                   Json(new { success = true }) :
                   Json(new { success = false, formWithErrorMessages = this.RenderPartialViewToString(MVC.PushNotification.Views.Edit, model) }));
        }