public async Task Update(Employee_Contact entity) { try { var lstEmp_contact = adbContext.employee_contact.Where(x => x.Emp_Contact_Id == entity.Emp_Contact_Id && x.Emp_Id == entity.Emp_Id).FirstOrDefault(); if (lstEmp_contact != null) { lstEmp_contact.Emp_Id = entity.Emp_Id; lstEmp_contact.Contact_Type = entity.Contact_Type; lstEmp_contact.Contact_Value = entity.Contact_Value; lstEmp_contact.isDefault = entity.isDefault; lstEmp_contact.Version_Id = entity.Version_Id; lstEmp_contact.isActive = entity.isActive; lstEmp_contact.UpdatedBy = entity.UpdatedBy; lstEmp_contact.UpdatedOn = DateTime.Now; adbContext.employee_contact.Update(lstEmp_contact); await Task.FromResult(adbContext.SaveChanges()); } else { throw new Exception("Data Not Available"); } } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Edit(Employee_Contact employee_Contact) { ResponseHelper objHelper = new ResponseHelper(); if (!ModelState.IsValid) { objHelper.Status = StatusCodes.Status424FailedDependency; objHelper.Message = "Invalid Model State"; return(BadRequest(objHelper)); } try { if (employee_ContactRepository.Exists(employee_Contact)) { objHelper.Status = StatusCodes.Status200OK; objHelper.Message = "Data already available"; return(Ok(objHelper)); } await employee_ContactRepository.Update(employee_Contact); objHelper.Status = StatusCodes.Status200OK; objHelper.Message = "Saved Successfully"; return(Ok(objHelper)); } catch { objHelper.Status = StatusCodes.Status500InternalServerError; objHelper.Message = "Get Unsuccessful"; return(StatusCode(StatusCodes.Status500InternalServerError, objHelper)); } }
public async Task Insert(Employee_Contact entity) { try { entity.AddedOn = DateTime.Now; adbContext.employee_contact.Add(entity); await Task.FromResult(adbContext.SaveChanges()); } catch (Exception ex) { throw ex; } }
public bool Exists(Employee_Contact entity) { try { int intCount = 0; if (entity.Emp_Contact_Id > 0) //Update Validation { intCount = adbContext.employee_contact.Where(w => w.Emp_Contact_Id != entity.Emp_Contact_Id && w.Emp_Id == entity.Emp_Id && w.Contact_Type == entity.Contact_Type && w.Contact_Value == entity.Contact_Value).Count(); } else //Insert Validation { intCount = adbContext.employee_contact.Where(w => w.Emp_Id == entity.Emp_Id && w.Contact_Type == entity.Contact_Type && w.Contact_Value == entity.Contact_Value).Count(); } return(intCount > 0 ? true : false); } catch (Exception ex) { throw ex; } }