コード例 #1
0
        private SACAAEContext db = new SACAAEContext(); // Database context

        #endregion Fields

        #region Methods

        /// GET: Plaza/Allocate/5
        /// <author>Adonis Mora Angulo</author>
        /// <summary>
        /// Initialize the view to allocate professors to a plaza
        /// </summary>
        /// <param name="id">Plaza's id</param>
        /// <returns></returns>
        public ActionResult Allocate(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Plaza vPlaza = db.Plazas.Find(id);
            if (vPlaza == null)
            {
                return HttpNotFound();
            }
            var vPlazaProfesorList = vPlaza.PlazasXProfessors.OrderByDescending(p => p.PercentHours)
                                                             .ThenBy(p => p.Professor.Name).ToList();
            var vProfessors = new List<PlazaAllocateProfessor>();
            vPlazaProfesorList.ForEach(p => vProfessors.Add(new PlazaAllocateProfessor()
            {
                ID = p.ProfessorID,
                Name = p.Professor.Name,
                Allocate = p.PercentHours
            }));

            var viewModel = new PlazaAllocateViewModel()
            {
                ID = vPlaza.ID,
                TotalAllocate = sumAllocate(vProfessors),
                Professors = vProfessors
            };

            return View(viewModel);
        }
コード例 #2
0
        public ActionResult Allocate(PlazaAllocateViewModel viewModel)
        {
            var vPlaza = db.Plazas.Find(viewModel.ID);
            var vNewProfe = viewModel.Professors.Last();
            vPlaza.PlazasXProfessors.Add(new PlazaXProfessor()
            {
                ProfessorID = vNewProfe.ID,
                PercentHours = vNewProfe.Allocate
            });
            db.SaveChanges();

            return RedirectToAction("Allocate", new { id = viewModel.ID });
        }
コード例 #3
0
        public ActionResult EditAllocate(PlazaAllocateViewModel viewModel)
        {
            var vPlazaID = viewModel.ID;
            var vProfeID = viewModel.Professors[0].ID;
            var vPlazaProfessor = db.PlazasXProfessors.Where(p => p.PlazaID == vPlazaID && p.ProfessorID == vProfeID).Single();
            vPlazaProfessor.PercentHours = viewModel.Professors[0].Allocate;

            db.Entry(vPlazaProfessor).State = EntityState.Modified;
            db.SaveChanges();

            return RedirectToAction("Allocate", new { id = viewModel.ID });
        }
コード例 #4
0
        public ActionResult DeleteAllocate(PlazaAllocateViewModel viewModel)
        {
            var vPlazaID = viewModel.ID;
            var vProfeID = viewModel.Professors[0].ID;
            var vPlazaProfessor = db.PlazasXProfessors.Where(p => p.PlazaID == vPlazaID && p.ProfessorID == vProfeID).Single();

            db.PlazasXProfessors.Remove(vPlazaProfessor);
            db.SaveChanges();

            return RedirectToAction("Allocate", new { id = viewModel.ID });
        }