public IActionResult CreateBoxType(BoxTypeVM boxTypeVM, IFormFile FilePicture) { try { PictureVM imageEntity = GeneratePicture.CreatePicture(FilePicture, $"{boxTypeVM.Name} - {boxTypeVM.Description}"); boxTypeVM.Picture = imageEntity; _boxApplicationService.AddBoxType(boxTypeVM); return(RedirectToAction("BoxesType")); } catch (CustomException exc) { throw exc; } catch (Exception ex) { throw ex; } }
public void AddBoxType(BoxTypeVM entity) { try { var boxType = _mapper.Map <BoxType>(entity); if (!boxType.ComponentValidator.Validate(boxType, new BoxTypeValidator())) { throw new CustomException(string.Join(", ", boxType.ComponentValidator.ValidationResult.Errors.Select(x => x.ErrorMessage))); } _unitOfWork.Repository <BoxType>().Add(boxType); _unitOfWork.CommitSync(); } catch (CustomException exc) { throw exc; } catch (Exception ex) { throw CustomException.Create <BoxApplicationService>("Unexpected error fetching add product", nameof(this.Add), ex); } }