예제 #1
0
        public async Task <IActionResult> Put(int id, [FromBody] ChoreViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var chore = _repo.GetChoreById(id);

                if (chore == null)
                {
                    return(NotFound());
                }

                _mapper.Map(viewModel, chore);

                if (await _repo.SaveAllAsync())
                {
                    return(Ok(_mapper.Map <ChoreViewModel>(chore)));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (System.Exception)
            {
                return(StatusCode(500));
            }
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] ChoreViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                var chore = _mapper.Map <Chore>(viewModel);
                _repo.AddEntity(chore);

                if (await _repo.SaveAllAsync())
                {
                    return(CreatedAtRoute(
                               "GetChore",
                               new { id = viewModel.ChoreId },
                               viewModel
                               ));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (System.Exception)
            {
                return(StatusCode(500));
            }
        }
예제 #3
0
        public ChoresControllerTests()
        {
            mockRepo   = new Mock <IHouseworkRepository>();
            mockMapper = new Mock <IMapper>();

            kitchen = new Room()
            {
                Id   = kitchenId,
                Name = "Kitchen"
            };
            kitchenViewModel = new RoomViewModel()
            {
                RoomId = kitchenId,
                Name   = "Kitchen"
            };

            mop = new Chore()
            {
                Id            = mopId,
                Name          = "Mop floors",
                LastCompleted = DateTime.Now,
                Frequency     = TimeSpan.FromDays(7),
                RoomId        = kitchenId
            };
            mopViewModel = new ChoreViewModel()
            {
                ChoreId   = mopId,
                Name      = "Mop floors",
                Frequency = TimeSpan.FromDays(7),
                RoomId    = kitchenId
            };

            controller = new ChoresController(mockRepo.Object, mockMapper.Object);
        }
예제 #4
0
        public ActionResult ChoreView()
        {
            ChoreViewModel model = new ChoreViewModel();

            model.ChoreList = db.chore;
            return(View(model));
        }
 public ChoreController(ApplicationDbContext db, IWebHostEnvironment hostingEnvironment)
 {
     _db = db;
     _hostingEnvironment = hostingEnvironment;
     ChoreVM             = new ChoreViewModel()
     {
         Category = _db.Category,
         Chore    = new Chore(),
         User     = _db.ApplicationUser
     };
 }
예제 #6
0
        public ActionResult ChoreView(ChoreViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.ChoreList = db.chore;

                var newChore = new Chore
                {
                    Chores = model.Chores
                };
                db.chore.Add(newChore);
                db.SaveChanges();
            }
            return(View(model));
        }
예제 #7
0
        // Navigation to Main Page
        public IActionResult MainPage()
        {
            ChoreViewModel choreviewmodel = new ChoreViewModel();

            choreviewmodel.Chores = _database.Chore;
            var users = _context.Users;

            foreach (var user in users)
            {
                user.Scores = _database.Scores.Where(s => s.User.Id == user.Id).ToList();
            }

            choreviewmodel.Users            = _context.Users;
            choreviewmodel.WeatherViewModel = _weatherViewModel;

            return(View(choreviewmodel));
        }