public async Task <IActionResult> PutChoreItem(int id, ChoreItem chore)
        {
            if (id != chore.Id)
            {
                return(BadRequest());
            }

            _dataContext.Entry(chore).State = EntityState.Modified;
            await _dataContext.SaveChangesAsync();

            return(Ok());
        }
        public async Task <IActionResult> CreateChoreItem([Bind("Name, isComplete,EndTime,Description,ChoreListId")] ChoreItem chore)
        {
            if (ModelState.IsValid)
            {
                _context.Add(chore);
                await _context.SaveChangesAsync();

                return(RedirectToAction("CreateChoreItem", new { id = chore.ChoreListId }));
            }

            return(View());
        }
Beispiel #3
0
        public ActionResult <IEnumerable <ChoreItem> > AddChore(ChoreItem chore)
        {
            var selectedAssignee = _dataContext.AssignedPerson.Where(x => x.Id == chore.AssignedTo.Id).FirstOrDefault();
            var selectedRoom     = _dataContext.Room.FirstOrDefault(x => x.Id == chore.Room.Id);

            chore.CreatedDate = DateTime.Now;
            chore.AssignedTo  = selectedAssignee;
            chore.Room        = selectedRoom;
            chore.StartDate   = DateTime.Now;
            chore.DueDate     = DateTime.Now.AddDays(10);
            _dataContext.ChoreItems.Add(chore);
            _dataContext.SaveChanges();
            var chores = _dataContext.ChoreItems.Include(x => x.AssignedTo).Include(x => x.Room).ToList();

            return(RedirectToAction("Index", chores));
        }
        public async Task <ActionResult <ChoreItem> > PostChoreItem(ChoreItem chore)
        {
            if (ModelState.IsValid)
            {
                var assigned = _dataContext.AssignedPerson.SingleOrDefault(x => x.Id == chore.AssignedTo.Id);
                chore.AssignedTo  = assigned;
                chore.CreatedDate = DateTime.Now;
                chore.StartDate   = DateTime.Now;
                chore.DueDate     = DateTime.Now.AddDays(10);
                _dataContext.ChoreItems.Add(chore);
                await _dataContext.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetChoreItem), new { id = chore.Id }, chore));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public IActionResult isCompleted(int id)
        {
            ChoreItem choreItem       = new ChoreItem();
            var       userId          = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var       SelectChoreItem = _context.ChoreItem.Where(e => e.Id == id).FirstOrDefault();

            choreItem = SelectChoreItem;
            if (choreItem.isCompleted)
            {
                choreItem.isCompleted = false;
            }
            else
            {
                choreItem.isCompleted = true;
            }
            _context.Update(choreItem);
            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }