示例#1
0
        public ActionResult <Family> Add(Family model)
        {
            if (!ModelState.IsValid)
            {
                model.FamilyMembers = _dbContext.FamilyMemebers.ToList();
                return(View("Index", model));
            }

            var newFamilyMember = new FamilyMember {
                FirstName       = model.newMemberFirstName,
                LastName        = model.newMemberLastName,
                PreferredName   = model.newMemberPreferredName,
                DateOfBirth     = model.newMemberDateOfBirth,
                CompletedChores = new List <CompletedChore>(),
                Redeptions      = new List <Redemption>()
            };

            _dbContext.FamilyMemebers.Add(newFamilyMember);
            _dbContext.SaveChanges();

            model = new Family {
                FamilyMembers = _dbContext.FamilyMemebers.ToList()
            };
            return(View("Index", model));
        }
        public IActionResult Add(Chores model)
        {
            if (!ModelState.IsValid)
            {
                model.ChoreList = _dbContext.Chores.ToList();
                return(View("Index", model));
            }

            var newChore = new Chore {
                Name        = model.newChoreName,
                Description = model.newChoreDescription,
                PointValue  = model.newChorePointValue
            };

            _dbContext.Chores.Add(newChore);
            _dbContext.SaveChanges();

            model = new Chores {
                ChoreList = _dbContext.Chores.ToList()
            };
            return(View("Index", model));
        }
        public IActionResult Add(Rewards model)
        {
            if (!ModelState.IsValid)
            {
                model.RewardList = _dbContext.Rewards.ToList();
                return(View("Index", model));
            }

            var newReward = new Reward {
                Cost        = model.newRewardCost,
                Name        = model.newRewardName,
                Description = model.newRewardDescription,
                IsEnabled   = true
            };

            _dbContext.Rewards.Add(newReward);
            _dbContext.SaveChanges();

            model = new Rewards {
                RewardList = _dbContext.Rewards.ToList()
            };

            return(View("Index", model));
        }