Exemplo n.º 1
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) }));
        }