public async Task <ServiceResponse <VatCategory> > Create(AddVatCategoryRequest request) { try { var vatCategory = new VatCategory { Code = GenerateCode(8), Description = request.Description, Name = request.Name }; var exist = await _baseRepository.GetByIdAndCode(vatCategory.Id, vatCategory.Code); if (exist != null) { return(new ServiceResponse <VatCategory>($"A Vat Category With the Provided Code and or Id Already Exist")); } var exist2 = await _baseRepository.FindOneByConditions(x => x.Name.ToLower().Equals(vatCategory.Name.ToLower())); if (exist2 != null) { return(new ServiceResponse <VatCategory>($"A Va tCategory With the Provided Name Already Exist")); } await _baseRepository.Create(vatCategory); return(new ServiceResponse <VatCategory>(vatCategory)); } catch (Exception ex) { return(new ServiceResponse <VatCategory>($"An Error Occured While Creating The Vat Category. {ex.Message}")); } }
public async Task <ActionResult> Create(AddVatCategoryViewModel request) { if (!ModelState.IsValid) { Alert($"Invalid Request.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } try { var addVatCategoryRequest = new AddVatCategoryRequest { Name = request.Name, Description = request.Description }; var result = await _vatCategoryService.Create(addVatCategoryRequest); if (!result.Success) { Alert($"{result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } Alert($"Vat Category Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { Alert($"Error! {ex.Message}.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }