예제 #1
0
        public async Task <IActionResult> Create(PartCreateInputModel model)
        {
            if (this.User.IsInRole(GlobalConstants.AdministratorRoleName))
            {
                if (!this.ModelState.IsValid)
                {
                    return(this.Redirect("/Part/Create"));
                }

                var ifPartExists = await this.partService.CheckIfPartExistsAsync(
                    model.PartName,
                    model.BrandAndModelName,
                    model.CategoryName,
                    model.ManufactoryName);

                if (ifPartExists)
                {
                    return(this.Redirect("/Part/Error"));
                }

                var dtoPartModel = PartCreateInputMapper.Map(model);
                await this.partService.CreatePartAsync(dtoPartModel);

                return(this.RedirectToAction("All", "Part", new { modelName = model.BrandAndModelName,
                                                                  categoryName = model.CategoryName }));
            }

            return(this.Redirect("/Identity/Account/AccessDenied"));
        }
예제 #2
0
        public static PartCreateInputDtoModel Map(PartCreateInputModel inputModel)
        {
            var model = new PartCreateInputDtoModel
            {
                PartName        = inputModel.PartName,
                ModelName       = inputModel.BrandAndModelName,
                CategoryName    = inputModel.CategoryName,
                ManufactoryName = inputModel.ManufactoryName,
                Quantity        = inputModel.Quantity,
                Price           = inputModel.Price,
            };

            return(model);
        }