public async Task Update(Ethinicity entity) { try { //Update Old Ethinicity Ethinicity lstEthinicity = new Ethinicity(); lstEthinicity = adbContext.ethinicity.Where(x => x.Id == entity.Id).FirstOrDefault(); if (lstEthinicity != null) { lstEthinicity.Ethnicity_Code = entity.Ethnicity_Code; lstEthinicity.Ethnicity_Name = entity.Ethnicity_Name; lstEthinicity.Language = entity.Language; lstEthinicity.Notes = entity.Notes; lstEthinicity.isActive = entity.isActive; lstEthinicity.UpdatedBy = entity.UpdatedBy; lstEthinicity.UpdatedOn = DateTime.Now; adbContext.ethinicity.Update(lstEthinicity); await Task.FromResult(adbContext.SaveChanges()); } else { throw new Exception("Data Not Available"); } } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Edit(Ethinicity ethinicity) { ResponseHelper objHelper = new ResponseHelper(); if (!ModelState.IsValid) { objHelper.Status = StatusCodes.Status424FailedDependency;; objHelper.Message = "Invalid Model State"; return(BadRequest(objHelper)); } try { if (ethinicityRepository.Exists(ethinicity)) { objHelper.Status = StatusCodes.Status200OK; objHelper.Message = "Data already available"; return(Ok(objHelper)); } await ethinicityRepository.Update(ethinicity); objHelper.Status = StatusCodes.Status200OK; objHelper.Message = "Saved Successfully"; objHelper.Data = ethinicity; return(Ok(objHelper)); } catch { objHelper.Status = StatusCodes.Status500InternalServerError; objHelper.Message = "Save Unsuccessful"; return(StatusCode(StatusCodes.Status500InternalServerError, objHelper)); } }
public async Task Insert(Ethinicity entity) { try { entity.AddedOn = DateTime.Now; adbContext.ethinicity.Add(entity); await Task.FromResult(adbContext.SaveChanges()); } catch (Exception ex) { throw ex; } }
public bool Exists(Ethinicity entity) { try { int intCount = 0; if (entity.Id > 0) //Update Validation { intCount = adbContext.ethinicity.Where(w => w.Id != entity.Id && (w.Ethnicity_Code == entity.Ethnicity_Code || w.Ethnicity_Name == entity.Ethnicity_Name)).Count(); } else //Insert Validation { intCount = adbContext.ethinicity.Where(w => w.Ethnicity_Code == entity.Ethnicity_Code || w.Ethnicity_Name == entity.Ethnicity_Name).Count(); } return(intCount > 0 ? true : false); } catch (Exception ex) { throw ex; } }