Example #1
0
        // GET: /Pomodoro/ChangeAction/5?parent=1
        public ActionResult ChangeAction(int?id, int?parent)
        {
            if (id == null || parent.HasValue == false)
            {
                return(Redirect(Request.GetReferrerUrlOrCurrent()));
            }
            Pomodoro pomo = db.GetPomodoroById(User, id.Value);

            if (pomo == null)
            {
                return(HttpNotFound());
            }
            if (pomo.Status == PomodoroStatus.Working || pomo.Status == PomodoroStatus.Unconfirmed)
            {
                //cannot perform change
                TempData["UpdateError"] = Settings.MSG_UNSUCCESSFUL_BECAUSE_WORKING;
                return(Redirect(Request.GetReferrerUrlOrCurrent()));
            }
            Action action = db.GetActionById(User, parent.Value);

            if (action == null)
            {
                return(HttpNotFound());
            }

            pomo.ActionID        = parent.Value;
            db.Entry(pomo).State = EntityState.Modified;
            db.SaveChanges();

            TempData["UpdateInfo"] = Settings.MSG_SUCCESSFUL_UPDATE;
            return(Redirect(Request.GetReferrerUrlOrCurrent()));
        }
Example #2
0
        public PartialViewResult Working()
        {
            WorkingPanelViewModel viewModel = new WorkingPanelViewModel();

            //(first) pomodoro with status = working(if exists)
            viewModel.pomodoro = db.GetMyPomodoros(User)
                                 .Where(p => p.Start.HasValue)
                                 .OrderByDescending(p => p.Start)
                                 .FirstOrDefault(p => p.Status == PomodoroStatus.Working);

            if (viewModel.pomodoro != null)
            {
                //target time reached -> pomodoro is completed
                if (viewModel.TargetTime <= DateTime.UtcNow)
                {
                    viewModel.pomodoro.Status          = PomodoroStatus.Unconfirmed;
                    db.Entry(viewModel.pomodoro).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }

            //not exists
            if (viewModel.pomodoro == null)
            {
                //(first) pomodoro with status = unconfirmed(if exists)
                viewModel.pomodoro = db.GetMyPomodoros(User)
                                     .Where(p => p.Start.HasValue)
                                     .OrderByDescending(p => p.Start)
                                     .FirstOrDefault(p => p.Status == PomodoroStatus.Unconfirmed);
            }

            if (viewModel.pomodoro != null)
            {
                viewModel.action = viewModel.pomodoro.Action;
            }
            else
            {
                var currentUser = manager.FindById(User.Identity.GetUserId());
                if (currentUser.ActionID.HasValue && currentUser.ActionID.Value > 0)
                {
                    viewModel.action = db.GetActionById(User, currentUser.ActionID.Value);
                }
            }
            if (viewModel.action != null)
            {
                ViewBag.ActionID = new SelectList(db.GetMyActions(User), "ID", "Name", viewModel.action);
            }
            else
            {
                ViewBag.ActionID = new SelectList(db.GetMyActions(User), "ID", "Name");
            }

            return(PartialView("Panels/_WorkingPanel", viewModel));
        }
Example #3
0
        // GET: /Action/Details/5
        public ActionResult LightDetails(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Action action = db.GetActionById(User, id.Value);

            if (action == null)
            {
                return(HttpNotFound());
            }
            return(View(action));
        }