public async Task <IActionResult> AddEmployees(CreateorEditEmployeeDto input) { try { var postId = await _employeeRepository.AddEmployee(input); if (postId > 0) { return(Ok(postId)); } else { return(NotFound()); } } catch (Exception ex) { return(BadRequest()); } }
public async Task UpdateEmployee(CreateorEditEmployeeDto input) { var getdata = _nursaryContext.EmployeeDetails.Where(x => x.Id == input.Id).FirstOrDefault(); getdata.NurseryId = input.NurseryId; getdata.FirstName = input.FirstName; getdata.MiddleName = input.MiddleName; getdata.LastName = input.LastName; getdata.StateId = input.StateId; getdata.DistrictId = input.DistrictId; getdata.Email = input.Email; getdata.ContactNumber = input.ContactNumber; getdata.CreationDate = DateTime.Now; getdata.IsDeleted = false; getdata.TehsilId = input.TehsilId; getdata.EducationType = input.EducationType; getdata.GenderType = input.GenderType; getdata.VillageName = input.VillageName; _nursaryContext.EmployeeDetails.Update(getdata); //Commit the transaction await _nursaryContext.SaveChangesAsync(); }
public async Task <IActionResult> UpdateEmployees(CreateorEditEmployeeDto input) { if (ModelState.IsValid) { try { await _employeeRepository.UpdateEmployee(input); return(Ok()); } catch (Exception ex) { if (ex.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException") { return(NotFound()); } return(BadRequest()); } } return(BadRequest()); }
public async Task <int> AddEmployee(CreateorEditEmployeeDto input) { EmployeeDetail cd = new EmployeeDetail(); cd.NurseryId = input.NurseryId; cd.FirstName = input.FirstName; cd.MiddleName = input.MiddleName; cd.LastName = input.LastName; cd.StateId = input.StateId; cd.DistrictId = input.DistrictId; cd.Email = input.Email; cd.ContactNumber = input.ContactNumber; cd.CreationDate = DateTime.Now; cd.IsDeleted = false; cd.TehsilId = input.TehsilId; cd.EducationType = input.EducationType; cd.GenderType = input.GenderType; cd.VillageName = input.VillageName; await _nursaryContext.EmployeeDetails.AddAsync(cd); await _nursaryContext.SaveChangesAsync(); return(input.Id); }