// GET: PostingPeriods/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostingPeriodsViewModel model = new PostingPeriodsViewModel() { PostingPeriods = db.PostingPeriod.Include(p => p.Calendar).Include(p => p.Posting) .OrderByDescending(c => c.Calendar.Year) .ThenBy(c => c.Calendar.PeriodName) .ThenBy(c => c.Posting.Name) .ToList(), PostingPeriod = db.PostingPeriod.Find(id), Year = 0, PeriodName = string.Empty }; int selectedYear = db.PostingPeriod.Include(p => p.Calendar).First(i => i.Id == id).Calendar.Year; string selectedPeriodName = db.PostingPeriod.Include(p => p.Calendar).First(i => i.Id == id).Calendar.PeriodName; ViewBag.Year = new SelectList(db.Calendar.Select(y => new { y.Year }).Distinct().OrderByDescending(y => y.Year), "Year", "Year", selectedYear); ViewBag.CalendarId = new SelectList(db.Calendar, "PeriodName", "PeriodName", selectedPeriodName); ViewBag.PostingId = new SelectList(db.Posting, "Id", "Name", db.PostingPeriod.Find(id).PostingId); return(View(model)); }
public ActionResult Edit(PostingPeriodsViewModel postingPeriodVM) { if (ModelState.IsValid) { postingPeriodVM.PostingPeriod.StartDate = db.PostingPeriod.Where(i => i.Id == postingPeriodVM.PostingPeriod.Id).Select(i => i.StartDate).FirstOrDefault(); postingPeriodVM.PostingPeriod.EndDate = db.PostingPeriod.Where(i => i.Id == postingPeriodVM.PostingPeriod.Id).Select(i => i.EndDate).FirstOrDefault(); postingPeriodVM.PostingPeriod.CalendarId = db.PostingPeriod.Where(i => i.Id == postingPeriodVM.PostingPeriod.Id).Select(i => i.CalendarId).FirstOrDefault(); postingPeriodVM.PostingPeriod.PostingId = db.PostingPeriod.Where(i => i.Id == postingPeriodVM.PostingPeriod.Id).Select(i => i.PostingId).FirstOrDefault(); db.Entry(postingPeriodVM.PostingPeriod).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Year = new SelectList(db.Calendar.Select(y => new { y.Year }).Distinct().OrderByDescending(y => y.Year), "Year", "Year"); ViewBag.CalendarId = new SelectList(db.Calendar, "PeriodName", "PeriodName", postingPeriodVM.PostingPeriod.CalendarId); ViewBag.PostingId = new SelectList(db.Posting, "Id", "Name", postingPeriodVM.PostingPeriod.PostingId); return(View(postingPeriodVM.PostingPeriod)); //if (ModelState.IsValid) //{ // db.Entry(postingPeriod).State = EntityState.Modified; // db.SaveChanges(); // return RedirectToAction("Index"); //} //ViewBag.Year = new SelectList(db.Calendar.Select(y => new { y.Year }).Distinct().OrderByDescending(y => y.Year), "Year", "Year"); //ViewBag.CalendarId = new SelectList(db.Calendar, "PeriodName", "PeriodName", postingPeriod.CalendarId); //ViewBag.PostingId = new SelectList(db.Posting, "Id", "Name", postingPeriod.PostingId); //return View(postingPeriod); }
public ActionResult Create(PostingPeriodsViewModel postingPeriodVM) { if (ModelState.IsValid) { Calendar calendar = db.Calendar.Where(p => p.PeriodName == postingPeriodVM.PeriodName).Where(y => y.Year == postingPeriodVM.Year).FirstOrDefault(); postingPeriodVM.PostingPeriod.CalendarId = calendar.Id; db.PostingPeriod.Add(postingPeriodVM.PostingPeriod); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Year = new SelectList(db.Calendar.Select(y => new { y.Year }).Distinct().OrderByDescending(y => y.Year), "Year", "Year"); ViewBag.CalendarId = new SelectList(db.Calendar, "PeriodName", "PeriodName", postingPeriodVM.PostingPeriod.CalendarId); ViewBag.PostingId = new SelectList(db.Posting, "Id", "Name", postingPeriodVM.PostingPeriod.PostingId); return(View(postingPeriodVM.PostingPeriod)); }
// GET: PostingPeriods public ActionResult Index() { PostingPeriodsViewModel model = new PostingPeriodsViewModel() { PostingPeriods = db.PostingPeriod.Include(p => p.Calendar).Include(p => p.Posting) .OrderByDescending(c => c.Calendar.Year) .ThenBy(c => c.Calendar.PeriodName) .ThenBy(c => c.Posting.Name) .ToList(), PostingPeriod = new PostingPeriod(), Year = 0, PeriodName = string.Empty }; ViewBag.Year = new SelectList(db.Calendar.Select(y => new { y.Year }).Distinct().OrderByDescending(y => y.Year), "Year", "Year"); ViewBag.CalendarId = new SelectList(db.Calendar, "PeriodName", "PeriodName"); ViewBag.PostingId = new SelectList(db.Posting, "Id", "Name"); return(View(model)); }