public ActionResult Create(LeavedViewModel model) { if (!ModelState.IsValid) { ViewBag.Types = new SelectList(Enum.GetValues(typeof(SerialType)).OfType <SerialType>().Where(x => x != SerialType.ADM)); ViewBag.ShowValidation = true; ViewBag.Faculties = new SelectList(ctx.Faculties, "FacultyId", "FacultyName", model.FacultyId); ViewBag.Courses = new SelectList(ctx.Courses, "CourseId", "CourseName", model.CourseId); return(View(model)); } var leaved = new Leaved() { FirstName = model.FirstName, LastName = model.LastName, FacultyId = model.FacultyId, CourseId = model.CourseId, LeavedDate = model.LeavedDate, Serial1 = model.Serial1, Serial2 = model.Serial2, SerialType = model.SerialType, Causes = model.Causes }; ctx.Leaves.Add(leaved); ctx.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(LeavedViewModel model) { if (!ModelState.IsValid) { ViewBag.Types = new SelectList(Enum.GetValues(typeof(SerialType)).OfType <SerialType>(), model.SerialType); ViewBag.ShowValidation = true; ViewBag.Faculties = new SelectList(ctx.Faculties, "FacultyId", "FacultyName", model.CurrentFaculty); ViewBag.Courses = new SelectList(ctx.Courses, "CourseId", "CourseName", model.CurrentCourse); return(View(model)); } var leaved = ctx.Leaves.Find(model.LeavedId); leaved.Serial1 = model.Serial1; leaved.Serial2 = model.Serial2; leaved.SerialType = model.SerialType; leaved.FirstName = model.FirstName; leaved.LastName = model.LastName; leaved.FacultyId = model.FacultyId; leaved.CourseId = model.CourseId; leaved.LeavedDate = model.LeavedDate; leaved.Causes = model.Causes; ctx.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Leaves public ActionResult Index() { var headers = new string[] { "Key", "Serial", "Nombre", "Apellidos", "Facultad", "Carrera", "Fecha" }; var rows = (from leaved in ctx.Leaves.ToList() select new { Key = leaved.LeavedId, Serial = $"{leaved.Serial1}-{leaved.Serial2}-{leaved.SerialType}", Nombre = leaved.FirstName, Apellidos = leaved.LastName, Facultad = leaved.Faculty.FacultyName, Carrera = leaved.Course.CourseName, Fecha = leaved.LeavedDate }); var model = new LeavedViewModel() { IndexTable = new TableViewModel("Bajas", headers, rows) }; return(View(model)); }