Ejemplo n.º 1
0
 private RosterModel CalculateRosterFields(int _RosterType, DateTime _StartDate, int _WorkMin, TimeSpan _DutyTime, string _Criteria, int _CriteriaValue, int _Shift, int _RotaAppID)
 {
     RosterModel _objstudentmodel = new RosterModel();
     try
     {
         int endPoint = 0;
         if (_RosterType == 2)
             endPoint = 7;
         else if (_RosterType == 3)
             endPoint = 15;
         else if (_RosterType == 4)
         {
             endPoint = System.DateTime.DaysInMonth(_StartDate.Year, _StartDate.Month);
         }
         else if (_RosterType == 5)
         {
             endPoint = 84;
         }
         _objstudentmodel._RosterAttributes = new List<RosterAttributes>();
         for (int i = 1; i <= endPoint; i++)
         {
             string _day = _StartDate.Date.ToString("dddd");
             string _date = _StartDate.Date.ToString("dd-MMM-yyyy");
             string _DTime = _DutyTime.Hours.ToString("00") + _DutyTime.Minutes.ToString("00");
             _objstudentmodel.Criteria = ConvertCriteriaAbrvToFull(_Criteria);
             _objstudentmodel.RotaAppID = _RotaAppID;
             _objstudentmodel.CriteriaValue = _CriteriaValue;
             _objstudentmodel.ShiftID = _Shift;
             _objstudentmodel.StartDate = _StartDate;
             _objstudentmodel.NoOfDays = endPoint;
             _objstudentmodel.CriteriaValueName = GetCriteriaValueName(_Criteria, _CriteriaValue);
             _objstudentmodel.ShiftName = db.Shifts.FirstOrDefault(ss => ss.ShiftID == _Shift).ShiftName;
             _objstudentmodel._RosterAttributes.Add(new RosterAttributes { ID = i, DateString = _date, Day = _day, DutyDate = _StartDate.Date, DutyTimeString = _DTime, DutyTime = _DutyTime, WorkMin = _WorkMin });
             _StartDate = _StartDate.AddDays(1);
         }
         RosterApp rosterApp = db.RosterApps.First(aa => aa.RotaApplD == _RotaAppID);
         rosterApp.DateEnded = _StartDate.AddDays(-1);
         db.SaveChanges();
         return _objstudentmodel;
     }
     catch (Exception ex)
     {
         return _objstudentmodel;
     }
 }
Ejemplo n.º 2
0
        private RosterModel CalculateRosterEditEntries(RosterApp rosterApp, List<Models.RosterDetail> rosterDetails)
        {
            Shift shift = db.Shifts.First(aa => aa.ShiftID == rosterApp.ShiftID);
            RosterModel _objmodel = new RosterModel();
            int i = 1;
            try
            {
                _objmodel._RosterAttributes = new List<RosterAttributes>();
                DateTime _StartDate = (DateTime)rosterApp.DateStarted;
                _objmodel.RotaAppID = rosterApp.RotaApplD;
                _objmodel.ShiftName = shift.ShiftName;
                switch (rosterApp.RosterCriteria)
                {
                    case "S":

                        break;
                    case "C":
                        _objmodel.CriteriaValueName = db.Crews.Where(aa => aa.CrewID == rosterApp.CriteriaData).First().CrewName;
                        break;
                    case "T":

                        break;
                    case "employee":

                        break;
                }
                while (_StartDate <= rosterApp.DateEnded)
                {
                    string _day = _StartDate.Date.ToString("dddd");
                    string _date = _StartDate.Date.ToString("dd-MMM-yyyy");
                    string _DTime="";
                    TimeSpan _DutyTime = new TimeSpan();
                    int _WorkMin = 0;
                    if (rosterDetails.Where(aa => aa.RosterDate == _StartDate).Count() > 0)
                    {
                        // from roster details
                        RosterDetail rotaDetail = rosterDetails.First(aa=>aa.RosterDate == _StartDate);
                        _DTime = rotaDetail.DutyTime.Value.Hours.ToString("00")+rotaDetail.DutyTime.Value.Minutes.ToString("00");
                        _WorkMin = (int)rotaDetail.WorkMin;
                        _DutyTime = (TimeSpan)rotaDetail.DutyTime;

                    }
                    else
                    {
                        //from shift

                        _DTime = shift.StartTime.Hours.ToString("00") + shift.StartTime.Minutes.ToString("00");
                        _WorkMin = CalculateShiftWorkMins(_StartDate,shift);
                        _DutyTime = shift.StartTime;
                    }
                    _objmodel._RosterAttributes.Add(new RosterAttributes { ID = i, DateString = _date, Day = _day, DutyDate = _StartDate.Date, DutyTimeString = _DTime, DutyTime = _DutyTime, WorkMin = _WorkMin });
                    _StartDate = _StartDate.AddDays(1);
                    i++;
                }
                _objmodel.NoOfDays = i;
                return _objmodel;
            }
            catch (Exception ex)
            {
                return _objmodel;
            }
        }