public IActionResult UpdateScheduleForWeek([FromBody] EmpScheduleRegistrationViewModel model) { try { var empSRDomain = Service <IEmpScheduleRegistrationDomain>(); var result = empSRDomain.UpdateScheduleForWeek(model); return(Ok(result)); } catch (Exception e) { return(StatusCode(500, new ResponseViewModel { Message = e.Message, Success = false })); } }
public ResponseViewModel CreateScheduleForWeek(EmpScheduleRegistrationViewModel model) { try { var empSRDRepo = _uow.GetService <IEmpScheduleRegistrationDetailsRepository>(); var empSRRepo = _uow.GetService <IEmpScheduleRegistrationRepository>(); var empSR = _mapper.Map <EmpScheduleRegistration>(model); var empSRDs = _mapper.Map <List <EmpScheduleRegistrationDetails> >(model.Details); using (var trans = _uow.BeginTransation()) { empSR.Emp = null; empSR.DateCreated = DateTime.Now; empSR.DateUpdated = DateTime.Now; empSRRepo.CreateScheduleForWeek(empSR); _uow.Save(); foreach (var item in empSRDs) { item.Active = true; item.EmpScheduleRegistrationId = empSR.Id; } empSRDRepo.CreateEmpSRDs(empSRDs); _uow.Save(); trans.Commit(); } return(new ResponseViewModel { Success = true, Message = "Create Successfull" }); } catch (Exception e) { return(new ResponseViewModel { Success = false, Message = e.Message }); } }
public ResponseViewModel UpdateScheduleForWeek(EmpScheduleRegistrationViewModel model) { try { var empSRRepo = _uow.GetService <IEmpScheduleRegistrationRepository>(); var empSRDRepo = _uow.GetService <IEmpScheduleRegistrationDetailsRepository>(); var empSR = _mapper.Map <EmpScheduleRegistration>(model); empSR.Emp = null; var oldDetails = empSRDRepo.GetEmpSRDs(model.Id).ToList(); var newDetails = _mapper.Map <List <EmpScheduleRegistrationDetails> >(model.Details); empSR.DateUpdated = DateTime.Now; foreach (var item in newDetails) { if (item.Id != 0) { foreach (var detail in oldDetails) { if (item.Id == detail.Id) { empSRDRepo.ActiveEmpSRD(detail); oldDetails.Remove(detail); break; } else { empSRDRepo.DeactiveEmpSRD(detail); } } } else { item.EmpScheduleRegistrationId = model.Id; item.EmpScheduleRegistration = null; empSRDRepo.CreateEmpSRD(item); } } foreach (var item in oldDetails) { empSRDRepo.DeactiveEmpSRD(item); } empSRRepo.Edit(empSR); _uow.Save(); return(new ResponseViewModel { Success = true, Message = "Update Successfull" }); } catch (Exception e) { return(new ResponseViewModel { Success = false, Message = e.Message }); } }