Exemplo n.º 1
0
        public async Task <IActionResult> AddPart(PartCreateBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            var carId = await this.partsService
                        .CreateAsync(
                model.CarId,
                model.Name,
                model.Number,
                model.Price,
                model.Quantity);

            if (!this.IsValidId(carId))
            {
                this.ShowNotification(NotificationMessages.InvalidOperation,
                                      NotificationType.Error);
                return(this.Redirect(WebConstants.HomeIndex));
            }

            this.ShowNotification(string.Format(NotificationMessages.PartCreateSuccessfull, model.Number),
                                  NotificationType.Success);

            return(this.Redirect(string.Format(WebConstants.EmployeesCarsServiceDetails, carId)));
        }
        public async Task <IActionResult> Create(PartCreateBindingModel partCreateBindingModel)
        {
            if (ModelState.IsValid)
            {
                PartServiceModel partServiceModel = AutoMapper.Mapper.Map <PartServiceModel>(partCreateBindingModel);
                var result = await _partService.Create(partServiceModel);

                if (result)
                {
                    return(this.RedirectToAction("All"));
                }

                this.ViewData["error"] = ControllerConstants.PartErrorMessage;
                return(this.View(partCreateBindingModel));
            }
            this.ViewData["error"] = ControllerConstants.InputErrorMessage;
            return(this.View(partCreateBindingModel));
        }