public ActionResult EditResearchHistory(int id) { Careerhistory careerhistory = db.Careerhistories.Find(id); if (careerhistory == null) { return(HttpNotFound()); } else { if (User.IsInRole("Administrator") || User.IsInRole("Superuser") || (careerhistory.UserProfileUserId == (int)Membership.GetUser().ProviderUserKey)) { CareerhistoryViewModel careerhistoryVM = new CareerhistoryViewModel { UserName = careerhistory.UserProfile.UserName, InstitutionID = careerhistory.InstitutionInstitutionID, StartTime = careerhistory.StartTime, EndTime = careerhistory.EndTime, CareerhistoryID = careerhistory.CareerhistoryID, InstitutionName = careerhistory.Institutions.InstitutionName, Position = careerhistory.Position, UserId = careerhistory.UserProfileUserId }; ViewBag.InstitutionList = new SelectList(db.Institutions.Where(i => i.Status == "Current").OrderBy(i => i.InstitutionName).AsEnumerable(), "InstitutionID", "InstitutionName", careerhistoryVM.InstitutionID); return(View(careerhistoryVM)); } else { return(HttpNotFound()); } } }
public ActionResult CreateResearchHistory(CareerhistoryViewModel careerhistoryVM) { if (ModelState.IsValid) { if (careerhistoryVM.StartTime > careerhistoryVM.EndTime) { ModelState.AddModelError(string.Empty, "Start date must be before end date"); ViewBag.InstitutionList = new SelectList(db.Institutions.Where(i => i.Status == "Current").OrderBy(i => i.InstitutionName).AsEnumerable(), "InstitutionID", "InstitutionName", careerhistoryVM.InstitutionID); return(View(careerhistoryVM)); } Careerhistory careerhistory = new Careerhistory(); careerhistory.InstitutionInstitutionID = careerhistoryVM.InstitutionID; careerhistory.UserProfileUserId = (int)Membership.GetUser(careerhistoryVM.UserName).ProviderUserKey; careerhistory.StartTime = careerhistoryVM.StartTime; careerhistory.EndTime = careerhistoryVM.EndTime; careerhistory.Position = careerhistoryVM.Position; careerhistory.Status = "Current"; careerhistory.LastUpdatedBy = (int)Membership.GetUser().ProviderUserKey; careerhistory.CreatedBy = (int)Membership.GetUser().ProviderUserKey; careerhistory.CreatedOn = DateTimeOffset.Now; db.Careerhistories.Add(careerhistory); db.SaveChanges(); return(RedirectToAction("ViewProfile", new { username = careerhistoryVM.UserName })); } ViewBag.InstitutionList = new SelectList(db.Institutions.Where(i => i.Status == "Current").OrderBy(i => i.InstitutionName).AsEnumerable(), "InstitutionID", "InstitutionName", careerhistoryVM.InstitutionID); return(View(careerhistoryVM)); }