Exemplo n.º 1
0
        //PUT /chores/edit/{id}
        public async Task <ActionResult> Edit(int id)
        {
            ChoresList item = await context.Chorelist.FindAsync(id);

            if (item == null)
            {
                return(NotFound("Chore not found"));
            }
            return(View(item));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Edit(ChoresList item)
        {
            //check to see if model is valid.
            if (ModelState.IsValid)
            {
                context.Update(item);
                await context.SaveChangesAsync();

                TempData["Success"] = "Chore has been updated!";
                //send the back to home page if successfully added to list.
                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Create(ChoresList item)
        {
            //check to see if model is valid.
            if (ModelState.IsValid)
            {
                var user = User.Identity.Name;
                item.listOwner = user;
                context.Add(item);
                await context.SaveChangesAsync();

                TempData["Success"] = "Chore has been added to list!";
                //send the back to home page if successfully added to list.
                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Delete(int id)
        {
            ChoresList item = await context.Chorelist.FindAsync(id);

            if (item == null)
            {
                TempData["Error"] = "The chore does not exist!";
            }
            else
            {
                context.Chorelist.Remove(item);
                await context.SaveChangesAsync();

                TempData["Success"] = "Chore has been deleted!";
            }
            return(RedirectToAction("Index"));
        }