Example #1
0
        public async Task <ActionResult> Create(
            [Bind(Include = "Id,Title,Content,HouseId,HouseFullAddress,CreationTime,ChangedTime")] AbonentNotificationModel model)
        {
            if (ModelState.IsValid)
            {
                using (var db = new ApplicationDbContext())
                {
                    var entity = new Notification
                    {
                        CreationTime = DateTime.Now,
                        Organization = await GetCurrentOrganization(db)
                    };

                    AbonentNotificationModel.ApplyToEntity(entity, model);
                    db.Notification.Add(entity);

                    await db.SaveChangesAsync();
                }
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Example #2
0
        public async Task <ActionResult> Edit(
            [Bind(Include = "Id,Title,Content")] AbonentNotificationModel model)
        {
            if (ModelState.IsValid)
            {
                using (var db = new ApplicationDbContext())
                {
                    var entity = (await db.Notification
                                  .FirstOrDefaultAsync(x => x.Id == model.Id));
                    if (entity == null)
                    {
                        return(HttpNotFound());
                    }

                    AbonentNotificationModel.ApplyToEntity(entity, model);

                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            return(View(model));
        }