Ejemplo n.º 1
0
        public async Task <ActionResult> AdminCreateCategory(CreateSupportCategoryModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("AdminCreateCategoryModal", model));
            }

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

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

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

                if (category != null)
                {
                    return(WriterResult <bool> .ErrorResult("Category with name '{0}' already exists.", model.Name));
                }

                context.SupportCategory.Add(new SupportCategory
                {
                    Name      = model.Name,
                    IsEnabled = true
                });
                await context.SaveChangesAsync();

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