public ActionResult Create(CreateCategoryModel vm)
        {
            try
            {
                //Check data validation
                if (!ModelState.IsValid)
                {
                    this.AddToastMessage(Messages.InvalidValueField, ToastType.Error);
                    return(View("Create", vm));
                }

                //Create Category
                _categoryService.Create(vm);

                //Successfully message
                this.AddToastMessage(string.Format(Messages.RecordSavedSuccessfully, "category"), ToastType.Success);

                return(RedirectToAction("Index"));
            }
            catch (CustomException ex)
            {
                this.AddToastMessage(ex.Message, ToastType.Error);
                return(View("Create", vm));
            }
            catch (Exception ex)
            {
                this.AddToastMessage(Messages.GeneralError, ToastType.Error);
                return(View("Create", vm));
            }
        }
Example #2
0
        public ActionResult Create(CreateCategoryInput viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    viewModel.CompanyName   = _currentUser.CompanyName;
                    viewModel.CreatorGuidId = _currentUser.CurrentUserId;
                    _categoryService.Create(viewModel);
                    ModelState.Clear();

                    var newVm = new CreateCategoryInput();
                    newVm.ErrorCode        = ErrorCodeHelper.Ok;
                    newVm.ErrorDescription = "¡Categoría guardada exitosamente!";
                    return(PartialView("_createPartial", newVm));
                }
                viewModel.ErrorCode        = ErrorCodeHelper.Error;
                viewModel.ErrorDescription = "Error al intentar guardar los datos.";
                return(PartialView("_createPartial", viewModel));
            }
            catch (Exception e)
            {
                viewModel.ErrorCode        = ErrorCodeHelper.Error;
                viewModel.ErrorDescription = e.Message;
                return(PartialView("_createPartial", viewModel));
            }
        }
Example #3
0
        public IActionResult Post([FromBody] CategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var categoryViewModel = _categoryAppService.Create(model);

            return(Ok(categoryViewModel));
        }
Example #4
0
        public async Task Add_Test()
        {
            // Act
            var output = await _categoryAppService.Create(new CategoryDto
            {
                Name = "1", PicUrl = "2"
            });

            // Assert
            Assert.NotEqual(0, output.Id);

            //output.Items.Count.ShouldBeGreaterThan(0);
        }
Example #5
0
        public IActionResult Create(CategoryViewModel categoryViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(categoryViewModel));
            }
            //categoryViewModel.CategoryId = Guid.NewGuid();

            _categoryAppService.Create(categoryViewModel);

            if (IsValidOperation())
            {
                ViewBag.Sucesso = "Category Created!";
            }

            return(View(categoryViewModel));
        }