public bool SaveCSVFileData(ResourceShift resourceShift, out string msg) { msg = ""; if (resourceShift != null) { Resource_ShiftSchedule resShift = new Resource_ShiftSchedule(); resShift.EmployeeID = (int)resourceShift.EmployeeID; resShift.ShiftPatternID = (int)resourceShift.ShiftPatternID; resShift.ShiftDate = (DateTime)resourceShift.ShiftDate; resShift.ExpectedOffTime = (DateTime)resourceShift.ExpectedOffTime; resShift.ExpectedOnTime = (DateTime)resourceShift.ExpectedOnTime; resShift.ActualOnTime = resourceShift.ActualOnTime; resShift.ActualOffTime = resourceShift.ActualOffTime; resShift.BranchID = (int)resourceShift.BranchID; _db.Resource_ShiftSchedule.Add(resShift); _db.SaveChanges(); msg = "Successfully Saved"; return(true); } return(false); }
/// <summary> /// Create ShiftSchedule /// </summary> /// <param name="shiftSchedule"></param> /// <returns></returns> public bool CreateShiftSchedule(ShiftScheduleViewModel shiftSchedule, out string msg) { msg = ""; Resource_ShiftSchedule resource_ShiftSchedule = new Resource_ShiftSchedule(); var resList = shiftSchedule.ResourceList.Where(x => x.ResourceCheck == true).ToList(); if (resList.Count != 0) { //foreach (var x in shiftSchedule.ResourceID) resList.ForEach(x => { if (shiftSchedule.YesNo == "No") { // var checkShift = _db.Resource_ShiftSchedule.Where(m => m.EmployeeID == x.ResourceID && m.ShiftDate == shiftSchedule.ShiftStartDate).Select(m => m.ShiftPatternID).ToList(); // var empID = int.Parse(x.ResourceID); var check = _db.Resource_ShiftSchedule.Where(m => m.EmployeeID == x.ResourceID && m.ShiftDate == shiftSchedule.ShiftStartDate).FirstOrDefault(); resource_ShiftSchedule.EmployeeID = x.ResourceID; resource_ShiftSchedule.ShiftDate = shiftSchedule.ShiftStartDate; resource_ShiftSchedule.ExpectedOnTime = shiftSchedule.ShiftStartDate.Add(shiftSchedule.ExpectedOnTime); resource_ShiftSchedule.ExpectedOffTime = shiftSchedule.ShiftEndDate.Add(shiftSchedule.ExpectedOffTime); resource_ShiftSchedule.ShiftPatternID = shiftSchedule.ShiftPatternID; resource_ShiftSchedule.BranchID = shiftSchedule.BranchNameID; if (shiftSchedule.ActualOnTime != null) { resource_ShiftSchedule.ActualOnTime = shiftSchedule.ShiftStartDate.Add((TimeSpan)shiftSchedule.ActualOnTime); } if (shiftSchedule.ActualOffTime != null) { resource_ShiftSchedule.ActualOffTime = shiftSchedule.ShiftEndDate.Add((TimeSpan)shiftSchedule.ActualOffTime); } _db.Resource_ShiftSchedule.Add(resource_ShiftSchedule); _db.SaveChanges(); //} } if (shiftSchedule.YesNo == "Yes") { // var emID = int.Parse(x); var checkYes = (from rss in _db.Resource_ShiftSchedule where rss.EmployeeID == x.ResourceID && rss.ShiftDate == shiftSchedule.ShiftStartDate select rss).ToList(); //var checkYes = _db.Resource_ShiftSchedule.Where(m => m.EmployeeID == int.Parse(x) && m.ShiftDate == shiftSchedule.ShiftStartDate).ToList(); if (checkYes.Count != 0) { //foreach (var p in checkYes) //{ checkYes.ForEach(p => { Resource_ShiftSchedule shift = _db.Resource_ShiftSchedule.Where(m => m.ShiftScheduleID == p.ShiftScheduleID).FirstOrDefault(); if (shift != null) { _db.Resource_ShiftSchedule.Remove(shift); _db.SaveChanges(); resource_ShiftSchedule.EmployeeID = x.ResourceID; resource_ShiftSchedule.ShiftDate = shiftSchedule.ShiftStartDate; resource_ShiftSchedule.ExpectedOnTime = shiftSchedule.ShiftStartDate.Add(shiftSchedule.ExpectedOnTime); resource_ShiftSchedule.ExpectedOffTime = shiftSchedule.ShiftEndDate.Add(shiftSchedule.ExpectedOffTime); resource_ShiftSchedule.ShiftPatternID = shiftSchedule.ShiftPatternID; resource_ShiftSchedule.BranchID = shiftSchedule.BranchNameID; if (shiftSchedule.ActualOnTime != null) { resource_ShiftSchedule.ActualOnTime = shiftSchedule.ShiftStartDate.Add((TimeSpan)shiftSchedule.ActualOnTime); } if (shiftSchedule.ActualOffTime != null) { resource_ShiftSchedule.ActualOffTime = shiftSchedule.ShiftEndDate.Add((TimeSpan)shiftSchedule.ActualOffTime); } _db.Resource_ShiftSchedule.Add(resource_ShiftSchedule); _db.SaveChanges(); } }); } else { resource_ShiftSchedule.EmployeeID = x.ResourceID; resource_ShiftSchedule.ShiftDate = shiftSchedule.ShiftStartDate; resource_ShiftSchedule.ExpectedOnTime = shiftSchedule.ShiftStartDate.Add(shiftSchedule.ExpectedOnTime); resource_ShiftSchedule.ExpectedOffTime = shiftSchedule.ShiftEndDate.Add(shiftSchedule.ExpectedOffTime); resource_ShiftSchedule.ShiftPatternID = shiftSchedule.ShiftPatternID; resource_ShiftSchedule.BranchID = shiftSchedule.BranchNameID; if (shiftSchedule.ActualOnTime != null) { resource_ShiftSchedule.ActualOnTime = shiftSchedule.ShiftStartDate.Add((TimeSpan)shiftSchedule.ActualOnTime); } if (shiftSchedule.ActualOffTime != null) { resource_ShiftSchedule.ActualOffTime = shiftSchedule.ShiftEndDate.Add((TimeSpan)shiftSchedule.ActualOffTime); } _db.Resource_ShiftSchedule.Add(resource_ShiftSchedule); _db.SaveChanges(); } } }); msg = "Successfully Created"; return(true); } msg = "Something Wrong"; return(false); }