//GET: /Comision/AsignarProfesorComision/5 public ActionResult AsignarProfesorComision(int?id) { if (Request.UrlReferrer != null) { ViewBag.returnUrl = Request.UrlReferrer.ToString(); } else { ViewBag.returnUrl = null; } Commission commission = db.Commissions.Find(id); ScheduleComissionViewModel commissionViewModel = new ScheduleComissionViewModel(); commissionViewModel.Commissions = commission.Name; ViewBag.Professors = new SelectList(db.Professors.OrderBy(p => p.Name), "ID", "Name");; ViewBag.CommissionID = commission.ID.ToString(); return(View(commissionViewModel)); }
//GET: Comision / EditarAsignacion/5 public ActionResult EditarAsignacion(int id) { if (Request.UrlReferrer != null) { ViewBag.returnUrl = Request.UrlReferrer.ToString(); } else { ViewBag.returnUrl = null; } var commission_profesor = db.CommissionsXProfessors.Find(id); var commissionID = commission_profesor.CommissionID; Commission commission = db.Commissions.Find(commissionID); ScheduleComissionViewModel commissionViewModel = new ScheduleComissionViewModel(); commissionViewModel.Commissions = commission.Name; ViewBag.Professors = new SelectList(db.Professors, "ID", "Name"); ViewBag.CommissionID = commissionID.ToString(); return(View(commissionViewModel)); }
public ActionResult Asignar(ScheduleComissionViewModel pSchedule) { var vPeriod = Request.Cookies["Periodo"].Value; var vPeriodID = db.Periods.Find(int.Parse(vPeriod)).ID; string vHourCharge = pSchedule.HourCharge; int vCommissionID = Convert.ToInt32(pSchedule.Commissions); int vProfessorID = Convert.ToInt32(pSchedule.Professors); List <ScheduleComission> vSchedules = pSchedule.ScheduleCommission; string validate = dbHelper.validationsCommission(vCommissionID, vProfessorID, vPeriodID, vSchedules); if (validate.Equals("true")) { int totalHourAssign = 0; //Save Commission Professor CommissionXProfessor vCommissionProfessor = new CommissionXProfessor(); vCommissionProfessor.CommissionID = Convert.ToInt32(vCommissionID); vCommissionProfessor.ProfessorID = Convert.ToInt32(vProfessorID); if (vHourCharge.Equals("1")) { vCommissionProfessor.HourAllocatedTypeID = Convert.ToInt32(vHourCharge); } vCommissionProfessor.PeriodID = vPeriodID; vCommissionProfessor.Schedule = new List <Schedule>(); //Calculate the total hour assign foreach (ScheduleComission vSchedule in vSchedules) { Schedule vTempSchedule = existSchedule(vSchedule.Day, vSchedule.StartHour, vSchedule.EndHour); if (vTempSchedule != null) { //Get id schedule vTempSchedule.CommissionsXProfessors.Add(vCommissionProfessor); } //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; } vCommissionProfessor.Hours = totalHourAssign; db.CommissionsXProfessors.Add(vCommissionProfessor); 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 a la comisión"; return(RedirectToAction("Asignar")); } else if (validate.Equals("falseIsProjectShock")) { TempData[TempDataMessageKeyError] = "Existe choque de horario con proyectos, no se asigno al profesor a la comisión"; return(RedirectToAction("Asignar")); } else if (validate.Equals("falseIsCommissionShock")) { TempData[TempDataMessageKeyError] = "Existe choque de horario con comisiones, no se asigno al profesor a la comisión"; return(RedirectToAction("Asignar")); } else if (validate.Equals("falseIsProfessorShock")) { TempData[TempDataMessageKeyError] = "El profesor ya esta asignado a esta comision, no se permite asignar dos veces a un profesor a una comisión "; return(RedirectToAction("Asignar")); } return(View()); }
public ActionResult EditarAsignacion(ScheduleComissionViewModel pSchedule) { var vPeriod = Request.Cookies["Periodo"].Value; var vPeriodID = db.Periods.Find(int.Parse(vPeriod)).ID; var vCommissionProfessorID = Convert.ToInt32(pSchedule.Commissions); var vHourCharge = Convert.ToInt32(pSchedule.HourCharge); var vProfessorID = Convert.ToInt32(pSchedule.Professors); if (ModelState.IsValid) { CommissionXProfessor vCommissionProfessor = db.CommissionsXProfessors.Find(vCommissionProfessorID); var vCommissionID = vCommissionProfessor.CommissionID; List <ScheduleComission> vSchedules = pSchedule.ScheduleCommission; string validate = dbHelper.validationsEditCommisson(vCommissionID, vProfessorID, vPeriodID, vSchedules); if (validate.Equals("true")) { vCommissionProfessor.ProfessorID = vProfessorID; vCommissionProfessor.HourAllocatedTypeID = Convert.ToInt32(vHourCharge); var totalHourAssign = 0; vCommissionProfessor.Schedule.Clear(); //Calculate the total hour assign foreach (ScheduleComission vSchedule in vSchedules) { Schedule vTempSchedule = existSchedule(vSchedule.Day, vSchedule.StartHour, vSchedule.EndHour); if (vTempSchedule != null) { //Get id schedule vTempSchedule.CommissionsXProfessors.Add(vCommissionProfessor); vCommissionProfessor.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; } vCommissionProfessor.Hours = totalHourAssign; db.SaveChanges(); TempData[TempDataMessageKeySuccess] = "Profesor asignado correctamente."; return(RedirectToAction("Details", new { id = vCommissionProfessor.CommissionID })); } else if (validate.Equals("falseIsGroupShock")) { TempData[TempDataMessageKeyError] = "Existe choque de horario con grupos, no se asigno al profesor a la comisión"; } else if (validate.Equals("falseIsProjectShock")) { TempData[TempDataMessageKeyError] = "Existe choque de horario con proyectos, no se asigno al profesor a la comisión"; } else if (validate.Equals("falseIsCommissionShock")) { TempData[TempDataMessageKeyError] = "Existe choque de horario con comisiones, no se asigno al profesor a la comisión"; } if (Request.UrlReferrer != null) { ViewBag.returnUrl = Request.UrlReferrer.ToString(); } else { ViewBag.returnUrl = null; } var commission_profesor = db.CommissionsXProfessors.Find(vCommissionProfessorID); var commissionID = commission_profesor.CommissionID; Commission commission = db.Commissions.Find(commissionID); ScheduleComissionViewModel commissionViewModel = new ScheduleComissionViewModel(); commissionViewModel.Commissions = commission.Name; ViewBag.Professors = new SelectList(db.Professors, "ID", "Name"); ViewBag.CommissionID = commission_profesor.CommissionID.ToString(); return(View(commissionViewModel)); } return(View()); }