public async Task <IActionResult> Edit(Employee_BasicInfo employee_BasicInfo) { ResponseHelper objHelper = new ResponseHelper(); if (!ModelState.IsValid) { objHelper.Status = StatusCodes.Status424FailedDependency; objHelper.Message = "Invalid Model State"; return(BadRequest(objHelper)); } try { if (employee_BasicInfoRepository.Exists(employee_BasicInfo)) { objHelper.Status = StatusCodes.Status200OK; objHelper.Message = "Data already available"; return(Ok(objHelper)); } await employee_BasicInfoRepository.Update(employee_BasicInfo); 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_BasicInfo entity) { try { if (entity != null) { entity.AddedOn = DateTime.Now; adbContext.employee_basicinfo.Add(entity); await Task.FromResult(adbContext.SaveChangesAsync()); } } catch (Exception ex) { throw ex; } }
public bool Exists(Employee_BasicInfo entity) { try { int intCount = 0; if (entity.BasicInfo_Id > 0) //Update Validation { intCount = adbContext.employee_basicinfo.Where(w => w.BasicInfo_Id != entity.BasicInfo_Id && w.Emp_Id == entity.Emp_Id && w.FirstName == entity.FirstName && w.MiddleName == entity.MiddleName && w.LastName == entity.LastName).Count(); } else //Insert Validation { intCount = adbContext.employee_basicinfo.Where(w => w.Emp_Id == entity.Emp_Id && w.FirstName == entity.FirstName && w.MiddleName == entity.MiddleName && w.LastName == entity.LastName).Count(); } return(intCount > 0 ? true : false); } catch (Exception ex) { throw ex; } }
public async Task Update(Employee_BasicInfo entity) { try { var lstEmp_basicinfo = adbContext.employee_basicinfo.Where(x => x.Emp_Id == entity.Emp_Id).FirstOrDefault(); if (lstEmp_basicinfo != null) { lstEmp_basicinfo.Emp_Id = entity.Emp_Id; lstEmp_basicinfo.FirstName = entity.FirstName; lstEmp_basicinfo.MiddleName = entity.MiddleName; lstEmp_basicinfo.LastName = entity.LastName; lstEmp_basicinfo.Title = entity.Title; lstEmp_basicinfo.DOB = entity.DOB; lstEmp_basicinfo.Gender = entity.Gender; lstEmp_basicinfo.BloodGroup = entity.BloodGroup; lstEmp_basicinfo.Nationality = entity.Nationality; lstEmp_basicinfo.Ethnicity_Code = entity.Ethnicity_Code; lstEmp_basicinfo.Version_Id = entity.Version_Id; lstEmp_basicinfo.isActive = entity.isActive; lstEmp_basicinfo.UpdatedBy = entity.UpdatedBy; lstEmp_basicinfo.UpdatedOn = DateTime.Now; adbContext.employee_basicinfo.Update(lstEmp_basicinfo); await Task.FromResult(adbContext.SaveChanges()); } else { throw new Exception("Data Not Available"); } } catch (Exception ex) { throw ex; } }
private string GenerateFullName(Employee_BasicInfo employee_BasicInfo) { return(employee_BasicInfo.FirstName + " " + employee_BasicInfo.LastName); }