public ActionResult CreateLight([Bind(Include = "ID,Name")] CollectedThing collectedthing, string submitButton, string UrlReferrer) { if (ModelState.IsValid) { //set owner UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); collectedthing.User = manager.FindById(User.Identity.GetUserId()); //set creation date collectedthing.CreationDate = DateTime.UtcNow; db.CollectedThings.Add(collectedthing); db.SaveChanges(); } UrlReferrer = UrlReferrer .Replace("?collecting=1", string.Empty) .Replace("&collecting=1", string.Empty); if (submitButton == "Save") { return(Redirect(UrlReferrer)); } //"Create more" return(Redirect(UrlReferrer + (UrlReferrer.Contains("?") ? "&" : "?") + "collecting=1")); }
//// GET: /Pomodoro/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Pomodoro pomodoro = db.GetPomodoroById(User, id.Value); if (pomodoro == null) { return(HttpNotFound()); } db.Pomodoros.Remove(pomodoro); db.SaveChanges(); return(Redirect(Request.GetReferrerUrlOrCurrent())); }
// // GET: /Work/Start public RedirectResult Start() { var currentUser = manager.FindById(User.Identity.GetUserId()); if (currentUser.WorkingPanelAvailable) { if (currentUser.ActionID.HasValue && currentUser.ActionID.Value > 0) { if (currentUser.Action.IsSelectable) { Pomodoro pomodoro = new Pomodoro(); pomodoro.Start = DateTime.UtcNow; pomodoro.Status = PomodoroStatus.Working; pomodoro.ActionID = currentUser.ActionID.Value; db.Entry(pomodoro).State = EntityState.Modified; db.Pomodoros.Add(pomodoro); } else { currentUser.ActionID = null; db.Entry(currentUser).State = EntityState.Modified; } db.SaveChanges(); } } return(Redirect(Request.GetReferrerUrlOrCurrent())); }
public ActionResult Create([Bind(Include = "ID,Code,Name,Description")] Tag tag) { if (ModelState.IsValid) { //set owner UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); tag.User = manager.FindById(User.Identity.GetUserId()); //set creation date tag.CreationDate = DateTime.UtcNow; db.Tags.Add(tag); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tag)); }
public ActionResult Start() { Pomodoro pomodoro = new Pomodoro(); pomodoro.Start = DateTime.UtcNow; pomodoro.Status = PomodoroStatus.Working; pomodoro.ActionID = Int32.Parse(Request.Form["ActionID"]); db.Entry(pomodoro).State = EntityState.Modified; db.Pomodoros.Add(pomodoro); db.SaveChanges(); return(RedirectToAction("TestPanels")); }
public ActionResult ListEdit(int[] selectedTasks, int?newStatus, int?newPriority) { if (selectedTasks != null && selectedTasks.Length > 0) { string[] selectedTags = GetArrayParamsFromRequest(Request.Form, "tag-"); if (newStatus.HasValue || newPriority.HasValue || selectedTags.Length > 0) { var tasksToUpdate = db.GetMyTasks(User) .Include(t => t.Tags) .Where(t => selectedTasks.ToList().Contains(t.ID)).ToList(); try { foreach (var task in tasksToUpdate) { if (newStatus.HasValue) { task.Status = (Status)newStatus.Value; } if (newPriority.HasValue) { task.Priority = (LevelExtended)newPriority.Value; } if (selectedTags != null && selectedTags.Length > 0) { SetTagsToTask(selectedTags, task); } db.Entry(task).State = EntityState.Modified; } TempData["UpdateInfo"] = Settings.MSG_SUCCESSFUL_UPDATE; db.SaveChanges(); } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } } } return(RedirectToAction("Index")); }
public ActionResult UserSettings(string Id, string FullName, string TimeZoneId) { if (ModelState.IsValid) { ApplicationUser dbUser = db.Users.Find(Id);//UserManager.FindById(User.Identity.GetUserId()); dbUser.FullName = FullName; dbUser.TimeZoneId = TimeZoneId; db.Entry(dbUser).State = EntityState.Modified; db.SaveChanges(); TempData["UpdateInfo"] = GTDoro.Core.Models.Settings.MSG_SUCCESSFUL_UPDATE; } return(RedirectToAction("MyAccount", "Layout")); }
public ActionResult CreateProject([Bind(Include = "ID,Code,Name,Description,Status,EndDate")] Project newProject) { int collectedThingID = 0; if (Request != null) { Int32.TryParse(Request.Params["collectedThingID"], out collectedThingID); } //set owner UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); ApplicationUser appUser = manager.FindById(User.Identity.GetUserId()); if (ModelState.IsValid) { //set owner newProject.User = appUser; //set creation date newProject.CreationDate = DateTime.UtcNow; //create project db.Projects.Add(newProject); if (collectedThingID > 0) { //delete associated collected thing CollectedThing collectedThing = db.GetCollectedThingById(User, collectedThingID); if (collectedThing != null) { db.CollectedThings.Remove(collectedThing); } } db.SaveChanges(); TempData["UpdateInfo"] = Settings.MSG_SUCCESSFUL_CREATE; if (Request != null && Url != null) //avoid null reference exceptions when testing { string button = Request.Form["submitButton"]; if (button == "1") { return(JavaScript("window.location = '" + Url.Action("Index") + "'")); } return(JavaScript("window.location = '" + Url.Action("Details", "Project", new { id = newProject.ID }) + "'")); } } ViewBag.NewProject = newProject; return(PartialView(new Workspace(appUser))); }
private void CreateUser() { UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); appUser = new ApplicationUser { UserName = EMAIL_ADDRESS_TESTER, Email = EMAIL_ADDRESS_TESTER, FullName = FULLNAME_TESTER, TimeZoneId = TIME_ZONE_TESTER }; var result = manager.Create(appUser, PASSWORD_TESTER); result = manager.SetLockoutEnabled(appUser.Id, false); result = manager.AddToRole(appUser.Id, "Admin"); db.SaveChanges(); manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); var genericIdentity = new GenericIdentity(EMAIL_ADDRESS_TESTER, "Forms"); List <Claim> claims = new List <Claim> { new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", EMAIL_ADDRESS_TESTER), new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", appUser.Id) }; genericIdentity.AddClaims(claims); user = new GenericPrincipal(genericIdentity, new string[] { "Admin" }); }