예제 #1
0
        public ActionResult Edit(LogsEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var newModel = new LogsEditViewModel
                {
                    Goals   = LogsUtility.GetGoalDropdown(),
                    GoalLog = model.GoalLog
                };

                return(View("Edit", newModel));
            }

            var goalLogInDb = _context.GoalLogs.SingleOrDefault(item => item.Id == model.GoalLog.Id);

            if (goalLogInDb == null)
            {
                return(RedirectToAction("Index", "Logs"));
            }

            goalLogInDb.Date         = model.GoalLog.Date;
            goalLogInDb.WasCompleted = model.GoalLog.WasCompleted;
            goalLogInDb.GoalId       = model.GoalLog.GoalId;

            _context.SaveChanges();

            return(RedirectToAction("Index", "Logs"));
        }
예제 #2
0
        public ActionResult Add(LogsAddViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var newModel = new LogsAddViewModel
                {
                    Goals   = LogsUtility.GetGoalDropdown(),
                    GoalLog = model.GoalLog
                };

                return(View("Add", newModel));
            }

            var log = new GoalLog
            {
                Date         = model.GoalLog.Date,
                WasCompleted = model.GoalLog.WasCompleted,
                GoalId       = model.GoalId
            };

            _context.GoalLogs.Add(log);
            _context.SaveChanges();

            return(RedirectToAction("Index", "Goal"));
        }
예제 #3
0
        public ActionResult Add()
        {
            var model = new LogsAddViewModel
            {
                Goals = LogsUtility.GetGoalDropdown()
            };

            return(View(model));
        }
예제 #4
0
        public ActionResult Edit(int id)
        {
            GoalLog log = _context.GoalLogs.SingleOrDefault(item => item.Id == id);

            if (log == null)
            {
                return(RedirectToAction("Index", "Logs"));
            }

            var model = new LogsEditViewModel
            {
                Goals   = LogsUtility.GetGoalDropdown(),
                GoalLog = log
            };

            return(View(model));
        }