Ejemplo n.º 1
0
        public IActionResult AddBehavior(BehaviorEditModel model)
        {
            if (!_studentData.Contains(model.StudentName))
            {
                ViewBag.Message = "Student name must already be added";
                return(View());
            }

            if (ModelState.IsValid)
            {
                var newBehavior = new Behavior();
                newBehavior.BehaviorName = model.BehaviorName;
                newBehavior.StudentName  = model.StudentName;
                newBehavior.Value        = model.Value;

                newBehavior = _behaviorData.Add(newBehavior);

                _studentData.EditAddCurrentTotal(model.StudentName, model.Value);
                _studentData.EditAddLifetimeTotal(model.StudentName, model.Value);

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View());
            }
        }
Ejemplo n.º 2
0
        public IActionResult DeleteBehavior(BehaviorEditModel model)
        {
            if (!_studentData.Contains(model.StudentName))
            {
                ViewBag.Message = "Student name must already be added";
                return(View());
            }

            if (ModelState.IsValid)
            {
                _studentData.EditDeleteCurrentTotal(model.StudentName, _behaviorData.GetByName(model.BehaviorName, model.StudentName).Value);
                _studentData.EditDeleteLifetimeTotal(model.StudentName, _behaviorData.GetByName(model.BehaviorName, model.StudentName).Value);

                _behaviorData.Delete(model.BehaviorName, model.StudentName);

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View());
            }
        }