Esempio n. 1
0
        public async Task <ActionResult> AdminUpdateCategory(UpdateSupportCategoryModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("AdminUpdateCategoryModal", model));
            }

            var result = await SupportWriter.AdminUpdateSupportCategory(User.Id(), model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View("AdminUpdateCategoryModal", model));
            }

            return(CloseModalRedirect(Url.Action("Index", "Admin")));
        }
Esempio n. 2
0
        public async Task <IWriterResult <bool> > AdminUpdateSupportCategory(string userId, UpdateSupportCategoryModel model)
        {
            using (var context = DataContextFactory.CreateContext())
            {
                var category = await context.SupportCategory.FirstOrDefaultNoLockAsync(x => x.Id == model.Id);

                if (category == null)
                {
                    return(WriterResult <bool> .ErrorResult("Category with id '{0}' not found.", model.Id));
                }

                category.Name      = model.Name;
                category.IsEnabled = model.IsEnabled;
                await context.SaveChangesAsync();

                return(WriterResult <bool> .SuccessResult());
            }
        }