Beispiel #1
0
        public async Task<ActionResult> Edit(int id)
        {
            var db = MaintDbContext;
            var role = await db.Roles.FirstOrDefaultAsync(x => x.RoleId == id);
            if (role == null)
            {
                return HttpNotFound();
            }
            var model = new RoleEditModel();
            model.FromEntity(role, false, ControllerContext);

            return Template(model.CreateTemplate(ControllerContext));
        }
Beispiel #2
0
        public async Task<ActionResult> Edit(RoleEditModel model, int id)
        {
            var role = await MaintDbContext.Roles.FirstOrDefaultAsync(x => x.RoleId == id);
            if (role == null) 
            {
                return HttpNotFound();
            }
            model.FromEntity(role, true, ControllerContext);
            if (!TryUpdateModel(role, model))
            {
                return Template(model.CreateTemplate(ControllerContext));
            }

            await MaintDbContext.SaveChangesAsync();
            await SetFlashAsync(new FlashMessage
            {
                Text = MaintCultureTextResources.SuccessToSave,
                MessageType = FlashMessageType.Success,
            });

            return Template(model.CreateTemplate(ControllerContext));
        }