public async Task <BaseEntity> SaveAndReturnEntityAsync(EthnicityDto entityDto) { var entity = _mapper.Map <Ethnicity>(entityDto); var result = await _repository.SaveAndReturnEntityAsync(entity); return(result); }
public IActionResult AddAnEthnicity([FromBody] EthnicityDto ethnicityDto) { if (ethnicityDto == null) { return(BadRequest(ModelState)); } if (_npRepo.EthnicityExists(ethnicityDto.Name)) { ModelState.AddModelError("", "Ethnicity already exists."); return(StatusCode(404, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // var ContactInfoObj = _mapper.Map<CreateEmployeeDto, ContactInfo>(createEmployeeDto); var ethnicityObj = _mapper.Map <EthnicityDto, Ethnicity>(ethnicityDto); // employeePIObj.ContactInfo = ContactInfoObj; if (!_npRepo.CreateEthnicity(ethnicityObj)) { ModelState.AddModelError("", $"Something went wrong when saving the record {ethnicityObj.Name}"); return(StatusCode(500, ModelState)); } return(Ok()); }
public async Task <EthnicityDto> PutEthnicity(int id, EthnicityDto model) { var url = CRMApiUri + "/Ethnicity/" + id; var result = await PutRequestToApi(url, model); return(result); }
public async Task <EthnicityDto> PostEthnicity(EthnicityDto model) { var url = CRMApiUri + "/Ethnicity"; var result = await PostRequestToApi(url, model); return(result); }
public async Task <IActionResult> Put(int id, [FromBody] EthnicityDto ethnicityDto) { if (id == 0 || ethnicityDto.Id == 0) { return(StatusCode(StatusCodes.Status400BadRequest, "Id needs to be greater than 0.")); } return(await SaveAndReturnEntityAsync(async() => await _ethnicityService.SaveAndReturnEntityAsync(ethnicityDto))); }
public async Task <IActionResult> Post([FromBody] EthnicityDto ethnicityDto) { if (ethnicityDto.Id != 0) { return(StatusCode(StatusCodes.Status400BadRequest, "Identity insert is not permitted.")); } return(await SaveAndReturnEntityAsync(async() => await _ethnicityService.SaveAndReturnEntityAsync(ethnicityDto))); }
public IActionResult Save(EthnicityDto model) { UpdateAuditInformation(model); if (!ModelState.IsValid) { GetStateSettings(ViewState.Write); return(PartialView("Edit", model)); } model = model.Id > 0 ? _lookupFacadeApiClient.PutEthnicity(model.Id, model).Result : _lookupFacadeApiClient.PostEthnicity(model).Result; if (!string.IsNullOrWhiteSpace(model.ErrorMessage)) { return(PartialView("Edit", model)); } return(Json(new { message = model.SuccessMessage })); }
public async Task <EthnicityDto> PutEthnicity(int id, EthnicityDto model) { return(await _ethnicityApiClient.PutEthnicity(id, model)); }
public async Task <EthnicityDto> PostEthnicity(EthnicityDto model) { return(await _ethnicityApiClient.PostEthnicity(model)); }
public async Task <int> SaveAsync(EthnicityDto entityDto) { var result = await SaveAndReturnEntityAsync(entityDto); return(result.Id); }
public static void CreateDummyData(DbContext context, bool execute = false) { if (!execute) { return; } using (context) { for (int i = 0; i < 8; i++) { var country = new CountryDto() { Name = $"Sri Lanka {i}", }; var ethnicity = new EthnicityDto() { Name = "Zoroastrian", }; var watchBrand = new WatchBrandDto() { Name = "Panerai", }; var hiking = new SpecificActivityDto() { Name = "Hiking" }; var cycling = new SpecificActivityDto() { Name = "Cycling" }; var jerking = new SpecificActivityDto() { Name = "Jerking" }; var activity = new ActivityDto() { Activities = new List <SpecificActivityDto>() { hiking, cycling, jerking, }, }; var customer = new CustomerDto() { BirthDate = DateTime.Now.AddYears(-54 + i), CustomerNumber = $"HY398{i}K07K", Tags = new List <TagDto>() { ethnicity, country, watchBrand, activity } }; context.Entry(ethnicity).State = EntityState.Added; context.Entry(country).State = EntityState.Added; context.Entry(activity).State = EntityState.Added; context.Entry(hiking).State = EntityState.Added; context.Entry(cycling).State = EntityState.Added; context.Entry(jerking).State = EntityState.Added; context.Entry(watchBrand).State = EntityState.Added; context.Entry(customer).State = EntityState.Added; } context.SaveChanges(); } }