Exemplo n.º 1
0
        //The following are the methods used in this controller.
        //*****************************************************************************************

        //Returns a view with a ChoreModel if all checks pass.
        private ActionResult ViewChoreById(int?id)
        {
            //Check for existing Id
            if (id == null)
            {
                return(NullIdEncountered());
            }

            using (var context = new RotatingChoresContext())
            {
                var chore = GetChoreById(id, context);
                //Check for chore in database
                if (chore != null)
                {
                    //Check if Chore is in user's group
                    if (IsGroupObject(chore.GroupId))
                    {
                        var choreModel = ChoreModel.ConvertFromChore(chore);
                        SetGroupMemberSelectList(context);
                        return(View(choreModel));
                    }
                    return(InvalidGroup());
                }
                return(ChoreNotFound());
            }
        }
Exemplo n.º 2
0
        public ActionResult MarkCompletePost(int?id)
        {
            using (var context = new RotatingChoresContext())
            {
                var chore = GetChoreById(id, context);
                if (chore != null && IsGroupObject(chore.GroupId))
                {
                    var group = GetUserGroup(context);
                    //Working with the model
                    var choreModel = ChoreModel.ConvertFromChore(chore);
                    //Change LastCompleted etc on model
                    choreModel.MarkComplete();
                    //Use model to update chore
                    choreModel.UpdateChore(context, chore);
                    //Assign chore to next available person.
                    choreModel.AdvanceChore(chore, group);
                    context.SaveChanges();
                    TempData["Message"] = "Chore marked complete! Good Job!";
                    return(RedirectToAction("Index"));
                }

                TempData["FailureMessage"] = "There was an issuse completing the chore.";
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 3
0
 public IActionResult EditChoreEdit(ChoreModel model)
 {
     choreService.UpdateStatusAsync(new ChoreServiceRefence.Chore {
         Id = model.Id, Status = (byte)model.Status
     }, AccountModel.GetInstace().Session).Wait();
     return(Chore(new HouseModel {
         Id = model.HouseId
     }));
 }
Exemplo n.º 4
0
 public IActionResult JoinChore(ChoreModel model)
 {
     choreService.JoinChoreAsync(new ChoreServiceRefence.Chore {
         Id = model.Id
     }, AccountModel.GetInstace().Session).Wait();
     return(Chore(new HouseModel {
         Id = model.HouseId
     }));
 }
Exemplo n.º 5
0
        public IActionResult Put(int id, [FromBody] ChoreModel updatedChore)
        {
            var chore = _choreService.Update(updatedChore.ToDomainModel());

            if (chore == null)
            {
                return(NotFound());
            }
            //UNSURE
            return(Ok(chore.ToApiModel()));
        }
Exemplo n.º 6
0
 public IActionResult CreateChore(ChoreModel model)
 {
     if (model.EndDate != null && model.Name != null)
     {
         choreService.CreateChoreAsync(new ChoreServiceRefence.Chore {
             Description = model.Name, DueDate = model.EndDate
         }, model.HouseId).Wait();
     }
     return(Chore(new HouseModel {
         Id = model.HouseId
     }));
 }
Exemplo n.º 7
0
        public IActionResult Post([FromBody] ChoreModel newChore)
        {
            try {
                _choreService.Add(newChore.ToDomainModel());
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("AddChore", ex.GetBaseException().Message);
                return(BadRequest(ModelState));
            }

            return(CreatedAtAction("Get", new { Id = newChore.Id }, newChore));
        }
Exemplo n.º 8
0
        public ActionResult Edit(ChoreModel model)
        {
            using (var context = new RotatingChoresContext())
            {
                var chore = model.GetRepresentedChore(context);

                model.UpdateChore(context, chore);
                ValidateAssignTo(chore);
                if (ModelState.IsValid && IsGroupObject(chore.GroupId))
                {
                    context.SaveChanges();
                    TempData["Message"] = "Chore has been updated!";
                    return(RedirectToAction("Index"));
                }
                SetGroupMemberSelectList(context);
                return(View(model));
            }
        }
Exemplo n.º 9
0
 // GET: Chore
 public ActionResult Index()
 {
     using (var context = new RotatingChoresContext())
     {
         var group = GetUserGroup(context);
         //Check to make sure the group is found and has chores
         if (group != null & group.Chores.Count > 0)
         {
             //"Index" model is of type List<ChoreModel>
             List <ChoreModel> chores = new List <ChoreModel>();
             foreach (var chore in group.Chores)
             {
                 chores.Add(ChoreModel.ConvertFromChore(chore));
             }
             return(View(chores));
         }
     }
     //If there are no chores in the group redirect to Add page;
     TempData["Message"] = "No chores yet, add one now!";
     return(RedirectToAction("Add"));
 }
Exemplo n.º 10
0
        public ActionResult Add(ChoreModel choreModel)
        {
            using (var context = new RotatingChoresContext())
            {
                var addingChore = context.Chores.Create();
                choreModel.UpdateChore(context, addingChore);

                ValidateAssignTo(addingChore);
                if (ModelState.IsValid)
                {
                    addingChore.GroupId = User.Identity.GetGroupId();
                    context.Chores.Add(addingChore);
                    context.SaveChanges();
                    TempData["Message"] = "New chore added!";
                    return(RedirectToAction("Index"));
                }

                //If there is a problem with the model
                SetGroupMemberSelectList(context);
                return(View(choreModel));
            }
        }
Exemplo n.º 11
0
 public IActionResult EditChore(ChoreModel model)
 {
     ViewBag.houseid = model.Id;
     return(View("EditChoreView", model));
 }