コード例 #1
0
        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());
                }
            }
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public ActionResult DeleteResearchHistory(int id = 0)
        {
            Careerhistory careerhistory = db.Careerhistories.Find(id);

            if (ModelState.IsValid)
            {
                if (User.IsInRole("Administrator") || User.IsInRole("Superuser") || (careerhistory.UserProfile.UserName == User.Identity.Name))
                {
                    careerhistory.Status        = "Deleted";
                    careerhistory.LastUpdatedBy = (int)Membership.GetUser().ProviderUserKey;
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("ViewProfile", new { username = careerhistory.UserProfile.UserName }));
        }