public bool DeleteRoster(int RosterAppID, int LoggedUserID)
        {
            RosterApp RApp = new RosterApp();

            //User uid = new User();
            RApp = db.RosterApps.First(rr => rr.RotaAppID == RosterAppID);
            if (RApp.UserID == LoggedUserID)
            {
                try
                {
                    List <RosterDetail> RAppDetail = new List <Models.RosterDetail>();
                    RAppDetail = db.RosterDetails.Where(aa => aa.RosterAppID == RosterAppID).ToList();
                    foreach (var item in RAppDetail)
                    {
                        db.RosterDetails.Remove(item);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                db.RosterApps.Remove(RApp);
                db.SaveChanges();
            }

            return(true);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            RosterApp rosterapp = db.RosterApps.Find(id);

            db.RosterApps.Remove(rosterapp);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #3
0
        public ActionResult RosterEdit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RosterApp           rosterApp     = db.RosterApps.First(aa => aa.RotaApplD == id);
            List <RosterDetail> rosterDetails = db.RosterDetails.Where(aa => aa.RosterAppID == id).ToList();

            return(View(CalculateRosterEditEntries(rosterApp, rosterDetails)));
        }
        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>();
                RosterApp rosterApp = db.RosterApps.First(aa => aa.RotaAppID == _RotaAppID);
                Shift     shift     = db.Shifts.First(aa => aa.ShiftID == rosterApp.ShiftID);
                _DutyTime = shift.StartTime;
                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 = GetWorkMins(_StartDate, shift)
                    });
                    _StartDate = _StartDate.AddDays(1);
                }
                rosterApp.DateEnded = _StartDate.AddDays(-1);
                db.SaveChanges();
                return(_objstudentmodel);
            }
            catch (Exception ex)
            {
                return(_objstudentmodel);
            }
        }
 public ActionResult Edit([Bind(Include = "RotaApplD,DateCreated,DateStarted,DateEnded,UserID,RosterCriteria,CriteriaData,Status,RotaTypeID,WorkMin,DutyTime,ShiftID")] RosterApp rosterapp)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rosterapp).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RotaTypeID = new SelectList(db.RosterTypes, "ID", "Name", rosterapp.RotaTypeID);
     ViewBag.ShiftID    = new SelectList(db.Shifts, "ShiftID", "ShiftName", rosterapp.ShiftID);
     return(View(rosterapp));
 }
        // GET: /RosterApp/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RosterApp rosterapp = db.RosterApps.Find(id);

            if (rosterapp == null)
            {
                return(HttpNotFound());
            }
            return(View(rosterapp));
        }
Example #7
0
        public ActionResult RosterContinue(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //RosterDetailsCustom _RosterDetails = new RosterDetailsCustom();
            //_RosterDetails.RosterDetails = db.RosterDetails.Where(aa => aa.RosterAppID == id).ToList();
            //RosterApp _RosterApp = new RosterApp();
            //_RosterApp = db.RosterApps.First(aa => aa.RotaApplD == id);
            //_RosterDetails
            RosterApp rosterApp = db.RosterApps.First(aa => aa.RotaApplD == id);

            return(View(CalculateRosterFields((int)rosterApp.RotaTypeID, (DateTime)rosterApp.DateEnded.Value.AddDays(1), (int)rosterApp.WorkMin, (TimeSpan)rosterApp.DutyTime, rosterApp.RosterCriteria, (int)rosterApp.CriteriaData, (int)rosterApp.ShiftID, (int)rosterApp.RotaApplD)));
        }
Example #8
0
        public ActionResult RosterDetail(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //RosterDetailsCustom _RosterDetails = new RosterDetailsCustom();
            //_RosterDetails.RosterDetails = db.RosterDetails.Where(aa => aa.RosterAppID == id).ToList();
            //RosterApp _RosterApp = new RosterApp();
            //_RosterApp = db.RosterApps.First(aa => aa.RotaApplD == id);
            ////_RosterDetails
            var       rosterdetails = db.RosterDetails.Where(aa => aa.RosterAppID == id).ToList();
            RosterApp rosterApp     = db.RosterApps.First(aa => aa.RotaApplD == id);

            return(View(CalculateRosterDetails(rosterdetails, rosterApp)));
        }
        // GET: /RosterApp/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RosterApp rosterapp = db.RosterApps.Find(id);

            if (rosterapp == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RotaTypeID = new SelectList(db.RosterTypes, "ID", "Name", rosterapp.RotaTypeID);
            ViewBag.ShiftID    = new SelectList(db.Shifts, "ShiftID", "ShiftName", rosterapp.ShiftID);
            return(View(rosterapp));
        }
Example #10
0
        private void SaveEditRosterEntries(List <RosterAttributes> rosters, int _RotaAppID)
        {
            RosterApp rotaApp = db.RosterApps.First(aa => aa.RotaApplD == _RotaAppID);
            Shift     shift   = db.Shifts.First(aa => aa.ShiftID == rotaApp.ShiftID);

            foreach (var roster in rosters)
            {
                if (isRosterValueChanged(roster, shift))
                {
                    RosterDetail rosterDetail = new RosterDetail();
                    rosterDetail.CriteriaValueDate = rotaApp.RosterCriteria.ToString() + rotaApp.CriteriaData.ToString() + roster.DutyDate.ToString("yyMMdd");
                    rosterDetail.CompanyID         = rotaApp.CompanyID;
                    rosterDetail.OpenShift         = shift.OpenShift;
                    rosterDetail.UserID            = rotaApp.UserID;
                    rosterDetail.RosterAppID       = _RotaAppID;
                    if (roster.WorkMin == 0)
                    {
                        rosterDetail.DutyCode = "R";
                    }
                    else
                    {
                        rosterDetail.DutyCode = "D";
                    }
                    if (roster.DutyTime == new TimeSpan(0, 0, 0))
                    {
                        rosterDetail.OpenShift = true;
                    }
                    else
                    {
                        rosterDetail.OpenShift = false;
                    }
                    rosterDetail.DutyTime   = roster.DutyTime;
                    rosterDetail.WorkMin    = (short)roster.WorkMin;
                    rosterDetail.RosterDate = roster.DutyDate;
                    db.RosterDetails.Add(rosterDetail);
                    db.SaveChanges();
                }
            }
        }
Example #11
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);
            }
        }
Example #12
0
        private List <RosterDetailAttributes> CalculateRosterDetails(List <Models.RosterDetail> rosterdetails, RosterApp rosterApp)
        {
            //List<RosterDetailModel> rdm = new List<RosterDetailModel>();
            List <RosterDetailAttributes> rda = new List <RosterDetailAttributes>();
            Shift shift = new Shift();

            shift = db.Shifts.First(aa => aa.ShiftID == rosterApp.ShiftID);
            DateTime            currentDate     = rosterApp.DateStarted.Value;
            List <RosterDetail> tempRotaDetails = new List <RosterDetail>();

            while (currentDate <= rosterApp.DateEnded)
            {
                RosterDetailAttributes rdaS = new RosterDetailAttributes();
                tempRotaDetails = rosterdetails.Where(aa => aa.RosterDate == currentDate).ToList();
                if (tempRotaDetails.Count > 0)
                {
                    rdaS.Changed  = true;
                    rdaS.Day      = tempRotaDetails.FirstOrDefault().RosterDate.Value.ToString("dddd");
                    rdaS.DutyCode = tempRotaDetails.FirstOrDefault().DutyCode;
                    rdaS.DutyDate = tempRotaDetails.FirstOrDefault().RosterDate.Value;
                    rdaS.DutyTime = (TimeSpan)tempRotaDetails.FirstOrDefault().DutyTime;
                    rdaS.WorkMin  = (short)tempRotaDetails.FirstOrDefault().WorkMin;
                }
                else
                {
                    rdaS.Changed = false;
                    rdaS.Day     = currentDate.ToString("dddd");
                    int wrkMin = CalculateDutyCode(shift, currentDate);
                    if (wrkMin == 0)
                    {
                        rdaS.DutyCode = "R";
                    }
                    else
                    {
                        rdaS.DutyCode = "D";
                    }
                    rdaS.DutyDate = currentDate;
                    rdaS.DutyTime = shift.StartTime;
                    rdaS.WorkMin  = wrkMin;
                }
                rda.Add(rdaS);
                currentDate = currentDate.AddDays(1);
            }
            return(rda);
        }
Example #13
0
        public ActionResult Create(FormCollection form)
        {
            int      _Shift              = Convert.ToInt32(Request.Form["ShiftList"].ToString());
            int      _RosterType         = Convert.ToInt32(Request.Form["RosterType"].ToString());
            DateTime _StartDate          = Convert.ToDateTime(Request.Form["dateStart"]);
            DateTime _EndDate            = Convert.ToDateTime(Request.Form["dateEndHidden"]);
            TimeSpan _DutyTime           = MyHelper.ConvertTime(Request.Form["dutyTime"]);
            int      _WorkMin            = Convert.ToInt16(Request.Form["mints"]);
            string   Criteria            = "";
            bool     check               = false;
            int      RosterCriteriaValue = 0;

            switch (Request.Form["cars"].ToString())
            {
            case "shift":
                RosterCriteriaValue = Convert.ToInt32(Request.Form["ShiftList"].ToString());
                Criteria            = "S";
                break;

            case "crew":
                RosterCriteriaValue = Convert.ToInt32(Request.Form["CrewList"].ToString());
                Criteria            = "C";
                break;

            case "section":
                RosterCriteriaValue = Convert.ToInt32(Request.Form["SectionList"].ToString());
                Criteria            = "T";
                break;

            case "employee":

                break;
            }
            if (check == false)
            {
                RosterApp ra = new RosterApp()
                {
                    DateStarted    = _StartDate,
                    DateEnded      = _EndDate.AddDays(-1),
                    DateCreated    = DateTime.Now,
                    RosterCriteria = Criteria,
                    CriteriaData   = RosterCriteriaValue,
                    DutyTime       = _DutyTime,
                    RotaTypeID     = (byte)_RosterType,
                    WorkMin        = (short)_WorkMin,
                    Status         = true,
                    ShiftID        = (byte)_Shift,
                    UserID         = Convert.ToInt32(Session["LogedUserID"].ToString())
                };
                db.RosterApps.Add(ra);
                db.SaveChanges();

                return(View(CalculateRosterFields(_RosterType, _StartDate, _WorkMin, _DutyTime, Criteria, RosterCriteriaValue, _Shift, ra.RotaApplD)));
            }
            else
            {
                ViewBag.RosterType  = new SelectList(db.RosterTypes.OrderBy(s => s.Name), "ID", "Name");
                ViewBag.ShiftList   = new SelectList(GetListOfShift(), "ShiftID", "ShiftName");
                ViewBag.CrewList    = new SelectList(db.Crews.OrderBy(s => s.CrewName), "CrewID", "CrewName");
                ViewBag.SectionList = new SelectList(db.Sections.OrderBy(s => s.SectionName), "SectionID", "SectionName");
                return(View("Index"));
            }
        }
        private List <RosterDetailAttributes> CalculateRosterDetails(List <Models.RosterDetail> rosterdetails, RosterApp rosterApp)
        {
            //List<RosterDetailModel> rdm = new List<RosterDetailModel>();
            List <RosterDetailAttributes> rda = new List <RosterDetailAttributes>();
            Shift shift = new Shift();

            shift = db.Shifts.First(aa => aa.ShiftID == rosterApp.ShiftID);
            DateTime            currentDate     = rosterApp.DateStarted.Value;
            List <RosterDetail> tempRotaDetails = new List <RosterDetail>();
            string Criteria = "";

            switch (rosterApp.RosterCriteria)
            {
            case "S":
                Criteria = "Applied on Shift: " + rosterApp.Shift.ShiftName;
                break;

            case "T":
                Criteria = "Applied on Section :" + db.Sections.Where(aa => aa.SectionID == rosterApp.CriteriaData).First().SectionName;
                break;

            case "C":
                Criteria = "Applied on Crew :" + db.Crews.Where(aa => aa.CrewID == rosterApp.CriteriaData).First().CrewName;
                break;

            case "E":
                Criteria = "Applied on Employee :" + db.Emps.Where(aa => aa.EmpID == rosterApp.CriteriaData).First().EmpName;
                break;
            }
            string _Date = "Date: " + rosterApp.DateStarted.Value.ToString("dd-MMM-yyyy") + "   TO   " + rosterApp.DateEnded.Value.ToString("dd-MMM-yyyy");

            while (currentDate <= rosterApp.DateEnded)
            {
                RosterDetailAttributes rdaS = new RosterDetailAttributes();
                tempRotaDetails = rosterdetails.Where(aa => aa.RosterDate == currentDate).ToList();
                if (tempRotaDetails.Count > 0)
                {
                    rdaS.Date     = _Date;
                    rdaS.Shift    = rosterApp.Shift.ShiftName;
                    rdaS.Criteria = Criteria;
                    rdaS.Changed  = true;
                    rdaS.Day      = tempRotaDetails.FirstOrDefault().RosterDate.Value.ToString("dddd");
                    rdaS.DutyCode = tempRotaDetails.FirstOrDefault().DutyCode;
                    rdaS.DutyDate = tempRotaDetails.FirstOrDefault().RosterDate.Value;
                    rdaS.DutyTime = (TimeSpan)tempRotaDetails.FirstOrDefault().DutyTime;
                    rdaS.WorkMin  = (short)tempRotaDetails.FirstOrDefault().WorkMin;
                }
                else
                {
                    rdaS.Date     = _Date;
                    rdaS.Shift    = rosterApp.Shift.ShiftName;
                    rdaS.Criteria = Criteria;
                    rdaS.Changed  = false;
                    rdaS.Day      = currentDate.ToString("dddd");
                    int wrkMin = CalculateDutyCode(shift, currentDate);
                    if (wrkMin == 0)
                    {
                        rdaS.DutyCode = "R";
                    }
                    else
                    {
                        rdaS.DutyCode = "D";
                    }
                    rdaS.DutyDate = currentDate;
                    rdaS.DutyTime = shift.StartTime;
                    rdaS.WorkMin  = wrkMin;
                }
                rda.Add(rdaS);
                currentDate = currentDate.AddDays(1);
            }
            return(rda);
        }