Ejemplo n.º 1
0
        public ActionResult RemoveLeave(int id)
        {
            //------------Background identity check-------------//
            if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(Redirect("/Home/Index"));
            }

            Collaborator coll = dal.GetCollaborator(System.Web.HttpContext.Current.User.Identity.Name);
            //--------------------------------------------------//

            Leave currentLeave = dal.GetLeave(id);

            // Transfer the leave days into the collab's available days
            if (currentLeave.Type == LeaveType.RTT)
            {
                coll.NbRTT = currentLeave.ComputeLengthLeave();
            }
            else if (currentLeave.Type == LeaveType.PAID)
            {
                coll.NbPaid = currentLeave.ComputeLengthLeave();
            }


            // Remove the ER
            dal.GetLeave(id).Status = LeaveStatus.CANCELED;

            dal.SaveChanges();

            return(Redirect("/Leave/Index"));
        }
Ejemplo n.º 2
0
        public CalendarVM(Leave leave, char gr)
        {
            Title = leave.Collaborator.LastName;              // + " ("+  leave.Collaborator.Service.Name +  ") - " + leave.Type.ToString() Name (Service) - LeaveType
            Desc  = "Du " + leave.StartDate.ToString("dd/MM/yyyy") + " au " + leave.EndDate.ToString("dd/MM/yyyy") +
                    "<br>Journées : " + leave.ComputeLengthLeave() * 0.5 +
                    "<br>(" + leave.Description + ")";

            Start_Date = leave.StartDate.ToString("yyyy-MM-dd");

            if (leave.EndMorningOrAfternoon.Contains("Après-midi"))
            {
                End_Date = leave.EndDate.AddDays(1).ToString("yyyy-MM-dd");
            }
            else
            {
                End_Date = leave.EndDate.ToString("yyyy-MM-dd");
            }

            Group = gr;
            Color = leave.Color;
        }
Ejemplo n.º 3
0
        [HttpPost]         // Backend call of UpdateLeave page
        public ActionResult UpdateLeave(Leave model)
        {
            //------------Background identity check-------------//
            if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(Redirect("/Home/Index"));
            }

            Collaborator coll = dal.GetCollaborator(System.Web.HttpContext.Current.User.Identity.Name);

            //--------------------------------------------------//


            // Create the leave
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Create the temp leave
            Leave tempToDb = new Leave
            {
                Collaborator            = coll,
                Type                    = model.Type,
                Description             = model.Description,
                EndDate                 = model.EndDate,
                StartDate               = model.StartDate,
                Status                  = LeaveStatus.PENDING_APPROVAL_1,
                StartMorningOrAfternoon = model.StartMorningOrAfternoon,
                EndMorningOrAfternoon   = model.EndMorningOrAfternoon,
                Treatment               = HelperModel.ComputeTreatmentLeave(coll)
            };


            if (!HasLeaveOverlap(tempToDb))             //check if there's no leaves falling on the same date
            {
                int leaveLength = tempToDb.ComputeLengthLeave();
                // if leave length inferior to available leave (for RTT and for PAID), allow the creation
                if ((leaveLength <= coll.NbPaid) && tempToDb.Type == LeaveType.PAID && leaveLength > 0)
                {
                    coll.NbPaid -= leaveLength;
                    dal.CreateLeave(tempToDb);
                    SendNotificationHelp(tempToDb);
                    dal.SaveChanges();
                }
                else if ((leaveLength <= coll.NbRTT) && tempToDb.Type == LeaveType.RTT && leaveLength > 0)
                {
                    coll.NbRTT -= leaveLength;
                    dal.CreateLeave(tempToDb);
                    SendNotificationHelp(tempToDb);
                    dal.SaveChanges();
                }
                else if (tempToDb.Type == LeaveType.OTHER && leaveLength > 0)                 //in that case, we don't check the number of remaining days (sick leave etc)
                {
                    dal.CreateLeave(tempToDb);
                    SendNotificationHelp(tempToDb);
                    dal.SaveChanges();
                }
                else                 // the user doesn't have enough leave days available, either for RTT or PAID
                {
                    // Error alert to the coll. The leave is not saved into the database.
                    TempData["alertMessage"] = "Le congé n'a pas pu être créé.";
                    return(View(model));
                }
            }
            else
            {
                // Error alert to the coll. The leave is not saved into the database.
                TempData["alertMessage"] = "Le congé n'a pas pu être créé. Un congé existe déjà pour le même intervalle.";
                return(View(model));
            }

            return(Redirect("/Leave/Index"));
        }