public static Boolean WorkingHrsTxn(WorkingHoursTxnVM workHrsTxn, SchedulingDbContext schedulingDbContext) { using (var dbContextTxn = schedulingDbContext.Database.BeginTransaction()) { try { //currently we are not adding or updating shift at employee level thats why commented out below code. --- ramavtar 30May'18 //foreach (ShiftsMasterModel s in workHrsTxn.Shifts) //{ // if (s.ShiftId > 0) // UpdateShiftMaster(schedulingDbContext, s); // else if (s.ShiftId == 0) // AddShiftMaster(schedulingDbContext, s); //} //assigning newly addded shiftid to map-data var index = 0; foreach (EmployeeShiftMap m in workHrsTxn.Maps) { if (m.EmployeeShiftMapId > 0) { UpdateEmpShiftMap(schedulingDbContext, m); } else if (m.EmployeeShiftMapId == 0) { m.ShiftId = workHrsTxn.Shifts[index].ShiftId; AddEmpShiftMap(schedulingDbContext, m); } index++; } dbContextTxn.Commit(); return(true); } catch (Exception ex) { dbContextTxn.Rollback(); throw ex; } } }
public string Post() { DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>(); SchedulingDbContext schDbContext = new SchedulingDbContext(connString); string reqType = this.ReadQueryStringData("reqType"); string str = this.ReadPostData(); try { #region Employee Schedule manage : Insert/Update schedules if (reqType == "manageEmpSchedules") { List <EmpSchedules> schedulesData = DanpheJSONConvert.DeserializeObject <List <EmpSchedules> >(str); Boolean Flag = false; Flag = SchedulingBL.ManageEmpSchedules(schedulesData, schDbContext); if (Flag) { responseData.Status = "OK"; responseData.Results = 1; } else { responseData.ErrorMessage = "check console for error details."; responseData.Status = "Failed"; } } #endregion #region Add Shift (Manage Shifts) else if (reqType == "AddShift") { ShiftsMasterModel shiftMaster = DanpheJSONConvert.DeserializeObject <ShiftsMasterModel>(str); shiftMaster.CreatedOn = System.DateTime.Now; schDbContext.ShiftsMaster.Add(shiftMaster); schDbContext.SaveChanges(); responseData.Status = "OK"; responseData.Results = shiftMaster; } #endregion #region Employee Working Hours manage Transaction else if (reqType == "EmpWokringHours") { WorkingHoursTxnVM workHrsTxnData = DanpheJSONConvert.DeserializeObject <WorkingHoursTxnVM>(str); Boolean Flag = false; Flag = SchedulingBL.WorkingHrsTxn(workHrsTxnData, schDbContext); if (Flag) { responseData.Status = "OK"; responseData.Results = 1; } else { responseData.ErrorMessage = "check console for error details."; responseData.Status = "Failed"; } } #endregion } catch (Exception ex) { responseData.Status = "Failed"; responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString(); } return(DanpheJSONConvert.SerializeObject(responseData, true)); }