//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()); } }
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")); } }
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 })); }
public IActionResult JoinChore(ChoreModel model) { choreService.JoinChoreAsync(new ChoreServiceRefence.Chore { Id = model.Id }, AccountModel.GetInstace().Session).Wait(); return(Chore(new HouseModel { Id = model.HouseId })); }
public IActionResult Put(int id, [FromBody] ChoreModel updatedChore) { var chore = _choreService.Update(updatedChore.ToDomainModel()); if (chore == null) { return(NotFound()); } //UNSURE return(Ok(chore.ToApiModel())); }
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 })); }
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)); }
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)); } }
// 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")); }
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)); } }
public IActionResult EditChore(ChoreModel model) { ViewBag.houseid = model.Id; return(View("EditChoreView", model)); }