예제 #1
0
 public ActionResult Edit(User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         TempData["SuccessMessage"] = "Profile successfully updated!";
         return RedirectToAction("Details", new { id = user.UserId });
     }
     return View(user);
 }
예제 #2
0
        //
        // GET return a user from username
        //
        // Updated to v2.0 w/ audit trail
        //
        // This runs on every page load to grab the username, but if for some reason the username is not in the database,
        // it adds the user to the database so he/she can edit his/her information (ie. add firstname, lastname, etc.)
        public ActionResult returnUser()
        {
            try
            {
                User user = db.Users.Where(b => b.Username.Equals(User.Identity.Name)).First();
                return PartialView(user);
            }
            catch (Exception ex)
            {
                User newUser = new User();
                newUser.Username = User.Identity.Name;

                db.Users.Add(newUser);
                db.SaveChanges();

                User newestUser = db.Users.Where(b => b.Username.Equals(User.Identity.Name)).First();
                TempData["NewUser"] = "******";
                TempData["Url"] = Url.Action("Edit", "User", new { id = newestUser.UserId, username = User.Identity.Name });
                return PartialView(newUser);
            }
        }
        //
        // GET: /Project/Delete/5
        /*
        public ActionResult Delete(int id = 0)
        {
            Project project = db.Projects.Find(id);
            if (project == null)
            {
                return HttpNotFound();
            }
            return View(project);
        }

        //
        // POST: /Project/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Project project = db.Projects.Find(id);
            db.Projects.Remove(project);
            db.SaveChanges();
            return RedirectToAction("Index");
        }*/
        /*protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
        */
        /*
         *
         * Project Leader Editing - the following three controllers allow access and modification of the project leader positions, whether it be
         *                              remove, add, or modify
         *     Updated to v2.0 w/ audit trail
        */
        public ActionResult ModifyProjectLeaders(int projectid, int modifyType, int userid = 0, string editorname = "default")
        {
            Project project = db.Projects.Find(projectid);
            User user = new User();
            if (userid != 0)
            {
                user = db.Users.Find(userid);
            }

            string editor = editorname.Replace("/", @"\");

            Mapper.CreateMap<ProjectVersion, ProjectVersion>();
            ProjectVersion currentVersion = project.CurrentVersion;
            ProjectVersion newVersion = Mapper.Map<ProjectVersion, ProjectVersion>(currentVersion);

            //Edit changeLog, changeTime, changedBy
            newVersion.EditedBy = db.Users.Where(b => b.Username == editor).First();
            newVersion.EditedOn = DateTime.Now;
            string successString;

            //Change log distinction
            string changeType;
            if (userid == 0){
                changeType = "removed";
                successString = user.FirstName + " " + user.LastName + " was successfully removed ";
                user.FirstName = "";
                user.LastName = "";

            } else {
                changeType = "changed";
                successString = user.FirstName + " " + user.LastName + " was successfully added ";
            }

            //Modify leader by modifyType
            if (modifyType == 0)
            {
                newVersion.Lead = user;
                newVersion.ChangeDescription = changeType + " lead, " + user.FirstName + " " + user.LastName;
                successString += "as lead";
            }
            else if (modifyType == 1)
            {
                newVersion.Owner = user;
                newVersion.ChangeDescription = changeType + " owner, " + user.FirstName + " " + user.LastName;
                successString += "as owner";
            }
            else if (modifyType == 2)
            {
                newVersion.Presenter = user;
                newVersion.ChangeDescription = changeType + " presenter, " + user.FirstName + " " + user.LastName;
                successString += "as presenter";
            }
            newVersion.parentId = projectid;

            project.CurrentVersion = newVersion;
            db.SaveChanges();

            TempData["SuccessMessage"] = successString;
            return RedirectToAction("Details", new { id = project.ProjectId });
        }