public CommonResponse AddUpdateEmployeeShift(AddUpdateOperatorShift data) { CommonResponse obj = new CommonResponse(); try { DateTime fdate = Convert.ToDateTime(data.fromDate).Date; DateTime tdate = Convert.ToDateTime(data.toDate).Date; var check = db.UnitworkccsTblemployeeshiftdetails.Where(m => m.Id == data.id && m.EmployeeId == data.employeeId && (m.FromDate.Date <= fdate && m.ToDate.Date >= tdate)).FirstOrDefault(); if (check == null) { UnitworkccsTblemployeeshiftdetails tblOperatorDetailsShift = new UnitworkccsTblemployeeshiftdetails(); tblOperatorDetailsShift.EmployeeId = Convert.ToInt32(db.UnitworkccsTbloperatordetails.Where(m => m.OpId == data.employeeId).Select(m => m.OpNo).FirstOrDefault()); tblOperatorDetailsShift.Shift = data.shift; tblOperatorDetailsShift.MachineIds = data.machineIds; tblOperatorDetailsShift.FromDate = fdate; tblOperatorDetailsShift.ToDate = tdate; tblOperatorDetailsShift.IsDeleted = 0; tblOperatorDetailsShift.CreatedOn = DateTime.Now; tblOperatorDetailsShift.CreatedBy = 1; db.UnitworkccsTblemployeeshiftdetails.Add(tblOperatorDetailsShift); db.SaveChanges(); obj.isStatus = true; obj.response = ResourceResponse.AddedSuccessMessage; } else { check.Shift = data.shift; check.MachineIds = data.machineIds; // check.FromDate = fdate; // check.ToDate = tdate; check.IsDeleted = 0; check.ModifiedOn = DateTime.Now; check.ModifiedBy = 2; db.SaveChanges(); obj.isStatus = true; obj.response = ResourceResponse.UpdatedSuccessMessage; } } catch (Exception e) { obj.isStatus = false; obj.response = ResourceResponse.FailureMessage; } return(obj); }
public async Task <IActionResult> AddUpdateEmployeeShift(AddUpdateOperatorShift data) { CommonResponse response = empshift.AddUpdateEmployeeShift(data); return(Ok(response)); }