Exemplo n.º 1
0
        public ActionResult EditarAsignacion(ScheduleProjectViewModel pSchedule)
        {
            var vPeriod   = Request.Cookies["Periodo"].Value;
            var vPeriodID = db.Periods.Find(int.Parse(vPeriod)).ID;

            var vProjectXProfessorID = Convert.ToInt32(pSchedule.Projects);
            var vHourChange          = Convert.ToInt32(pSchedule.HourCharge);
            var vProfessorID         = Convert.ToInt32(pSchedule.Professors);

            if (ModelState.IsValid)
            {
                ProjectXProfessor vProjectXProfessor = db.ProjectsXProfessors.Find(vProjectXProfessorID);
                var vProjectID = vProjectXProfessor.ProjectID;

                List <ScheduleProject> vSchedules = pSchedule.ScheduleProject;
                string validate = dbHelper.validationsEditProject(vProjectID, vProfessorID, vPeriodID, vSchedules);
                if (validate.Equals("true"))
                {
                    vProjectXProfessor.ProfessorID         = vProfessorID;
                    vProjectXProfessor.HourAllocatedTypeID = Convert.ToInt32(vHourChange);
                    var totalHourAssign = 0;
                    vProjectXProfessor.Schedule.Clear();

                    //Calculate the total hour assign
                    foreach (ScheduleProject vSchedule in vSchedules)
                    {
                        Schedule vTempSchedule = existSchedule(vSchedule.Day, vSchedule.StartHour, vSchedule.EndHour);


                        if (vTempSchedule != null)
                        {
                            //Get id schedule

                            vTempSchedule.ProjectsXProfessors.Add(vProjectXProfessor);
                            vProjectXProfessor.Schedule.Add(vTempSchedule);
                        }


                        //Convert StartHour to DateTime
                        var vStartHour = DateTime.Parse(vSchedule.StartHour);
                        var vEndHour   = DateTime.Parse(vSchedule.EndHour);

                        var CargaC = Math.Ceiling(vEndHour.Subtract(vStartHour).TotalHours);

                        int vDiferencia = Convert.ToInt32(CargaC);


                        totalHourAssign = totalHourAssign + vDiferencia;
                    }


                    vProjectXProfessor.Hours = totalHourAssign;
                    db.SaveChanges();

                    TempData[TempDataMessageKeySuccess] = "Profesor asignado correctamente";
                    return(RedirectToAction("Details", new { id = vProjectXProfessor.ProjectID }));
                }
                else if (validate.Equals("falseIsProjectShock"))
                {
                    TempData[TempDataMessageKeyError] = "Existe choque de horario con proyectos, no se asigno al profesor al proyecto";
                }


                else if (validate.Equals("falseIsGroupShock"))
                {
                    TempData[TempDataMessageKeyError] = "Existe choque de horario con grupos, no se asigno al profesor al proyecto";
                }

                else if (validate.Equals("falseIsCommissionShock"))
                {
                    TempData[TempDataMessageKeyError] = "Existe choque de horario con comisiones, no se asigno al profesor a la comisión";
                }

                /* Get the list of professor related with project */
                if (Request.UrlReferrer != null)
                {
                    ViewBag.returnUrl = Request.UrlReferrer.ToString();
                }
                else
                {
                    ViewBag.returnUrl = null;
                }

                var     ProjectsXProfessors = db.ProjectsXProfessors.Find(vProjectXProfessorID);
                var     projectID           = ProjectsXProfessors.ProjectID;
                Project project             = db.Projects.Find(projectID);
                ScheduleProjectViewModel projectViewModel = new ScheduleProjectViewModel();
                projectViewModel.Projects = project.Name;

                ViewBag.Professors = new SelectList(db.Professors, "ID", "Name");
                ViewBag.ProjectID  = projectID.ToString();
                return(View(projectViewModel));
            }

            return(View());
        }
        public ActionResult Asignar(ScheduleProjectViewModel pSchedule)
        {
            var vPeriod   = Request.Cookies["Periodo"].Value;
            var vPeriodID = db.Periods.Find(int.Parse(vPeriod)).ID;

            string vHourCharge  = pSchedule.HourCharge;
            int    vProjectID   = Convert.ToInt32(pSchedule.Projects);
            int    vProfessorID = Convert.ToInt32(pSchedule.Professors);
            List <ScheduleProject> vSchedules = pSchedule.ScheduleProject;

            string validate = scheduleHelper.validationProject(vProjectID, vProfessorID, vPeriodID, vSchedules);

            if (validate.Equals("true"))
            {
                int totalHourAssign = 0;

                //Save Commission Professor
                ProjectXProfessor vProjectProfessor = new ProjectXProfessor();
                vProjectProfessor.ProjectID   = Convert.ToInt32(vProjectID);
                vProjectProfessor.ProfessorID = Convert.ToInt32(vProfessorID);
                if (vHourCharge.Equals("1"))
                {
                    vProjectProfessor.HourAllocatedTypeID = Convert.ToInt32(vHourCharge);
                }
                vProjectProfessor.PeriodID = vPeriodID;
                vProjectProfessor.Schedule = new List <Schedule>();

                //Calculate the total hour assign
                foreach (ScheduleProject vSchedule in vSchedules)
                {
                    Schedule vTempSchedule = existSchedule(vSchedule.Day, vSchedule.StartHour, vSchedule.EndHour);
                    if (vTempSchedule != null)
                    {
                        //Get id schedule

                        vTempSchedule.ProjectsXProfessors.Add(vProjectProfessor);
                    }

                    //Convert StartHour to DateTime
                    var HoraInicio = DateTime.Parse(vSchedule.StartHour);
                    //Convert EndHour to DateTime
                    var HoraFin = DateTime.Parse(vSchedule.EndHour);

                    //Get the difference between StartHour and EndHour
                    var vSTRDiff = Math.Ceiling(HoraFin.Subtract(HoraInicio).TotalHours);


                    int vDiferencia = Convert.ToInt32(vSTRDiff);

                    totalHourAssign = totalHourAssign + vDiferencia;
                }


                vProjectProfessor.Hours = totalHourAssign;

                db.ProjectsXProfessors.Add(vProjectProfessor);

                db.SaveChanges();
                TempData[TempDataMessageKeySuccess] = "Profesor asignado correctamente.";

                return(RedirectToAction("Asignar"));
            }
            else if (validate.Equals("falseIsGroupShock"))
            {
                TempData[TempDataMessageKeyError] = "Existe choque de horario con grupos, no se asigno al profesor al proyecto";
                return(RedirectToAction("Asignar"));
            }
            else if (validate.Equals("falseIsProjectShock"))
            {
                TempData[TempDataMessageKeyError] = "Existe choque de horario con proyectos, no se asigno al profesor al proyecto";
                return(RedirectToAction("Asignar"));
            }
            else if (validate.Equals("falseIsCommissionShock"))
            {
                TempData[TempDataMessageKeyError] = "Existe choque de horario con comisiones, no se asigno al profesor al proyecto";
                return(RedirectToAction("Asignar"));
            }
            else if (validate.Equals("falseIsProfessorShock"))
            {
                TempData[TempDataMessageKeyError] = "El profesor ya esta asignado a este proyecto, no se permite asignar dos veces a un profesor a un proyecto ";
                return(RedirectToAction("Asignar"));
            }
            return(View());
        }
Exemplo n.º 3
0
        //GET: Proyecto /DetalleAsignacion/5
        public ActionResult DetalleAsignacion(int id)
        {
            ProjectXProfessor project_profesor = db.ProjectsXProfessors.Find(id);

            return(View(project_profesor));
        }