public EnergyFile SaveFile(EnergyFile file) { try { using (var ctx = new DB_121539_alkeshpatelfEntities()) { ctx.EnergyFiles.Add(file); ctx.SaveChanges(); return(file); } } catch (Exception ex) { throw ex; } }
/* * Save EnergyPlan * * */ public EnergyPlan SaveEnergyPlan(EnergyPlan energyPlan) { try { using (var ctx = new DB_121539_alkeshpatelfEntities()) { energyPlan.CreateDate = DateTime.Now; ctx.EnergyPlans.Add(energyPlan); ctx.SaveChanges(); return(energyPlan); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Delete all schedules /// /// </summary> /// <returns>int value</returns> public int DeleteAllSchedules() { try { using (var ctx = new DB_121539_alkeshpatelfEntities()) { var scheduleItems = ctx.Schedules.Where(s => s.ScheduleId > 0); ctx.Schedules.RemoveRange(scheduleItems); ctx.SaveChanges(); return(1); } } catch (Exception ex) { } return(0); }
/* * Save Customer * * */ public Customer SaveCustomer(Customer customer) { try { using (var ctx = new DB_121539_alkeshpatelfEntities()) { customer.CreateDate = DateTime.Now; ctx.Customers.Add(customer); ctx.SaveChanges(); return(customer); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Assign Engineer /// /// </summary> /// <param name="selectedDate">Date on which engineer selected</param> /// <returns>int value</returns> public int AssignEngineer(DateTime selectedDate) { try { EngineerService engineerService = new EngineerService(); EngineerModel engineerModel = engineerService.GetQualifiedEngineer(selectedDate); if (engineerModel != null) { using (var ctx = new DB_121539_alkeshpatelfEntities()) { var scheduleItems = ctx.Schedules.Where(s => s.ScheduleDate == selectedDate); if (scheduleItems.Count() < 2) { var period = scheduleItems.Select(s => s.SchedulePeriod).FirstOrDefault(); int engineerPeriod = 1; if (period == 1) { engineerPeriod = 2; } Schedule schedule = new Schedule(); schedule.SchedulePeriod = engineerPeriod; schedule.ScheduleEngineer = engineerModel.EngineerId; schedule.CreateDate = DateTime.Now; schedule.UpdateDate = DateTime.Now; schedule.ScheduleDate = selectedDate; ctx.Schedules.Add(schedule); ctx.SaveChanges(); return(schedule.ScheduleId); } } } } catch (Exception ex) { } return(0); }