public ActionResult DeletePost(int?id)
 {
     using (var context = new RotatingChoresContext())
     {
         var doer = GetDoerById(id, context);
         if (doer != null)
         {
             if (IsGroupObject(doer.GroupId))
             {
                 try
                 {
                     context.ChoreDoers.Remove(doer);
                     context.SaveChanges();
                     TempData["Message"] = "Chore doer successfully deleted!";
                     return(RedirectToAction("Index", "Doer"));
                 }
                 catch (System.Data.Entity.Infrastructure.DbUpdateException)
                 {
                     TempData["FailureMessage"] = "Member must not have chores assigned or be the last to complete a chore.";
                     return(RedirectToAction("Index", "Chores"));
                 }
             }
             return(InvalidGroup());
         }
         return(DoerNotFound());
     }
 }
Beispiel #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"));
            }
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Name, Email = model.Email
                };

                //Check the existing ChoreDoers for the email from the user.
                using (var context = new RotatingChoresContext())
                {
                    var check = context.ChoreDoers.SingleOrDefault(d => d.Email.ToLower() == user.Email.ToLower());
                    if (check == null)
                    {
                        //If no ChoreDoer found by user's email, create new group -
                        var newGroup = context.Groups.Create();
                        //Add to the databse and save for auto increment value
                        context.Groups.Add(newGroup);
                        context.SaveChanges();
                        //And set to new GroupId
                        user.GroupId = newGroup.GroupId;
                    }
                    else
                    {
                        //If user email is found, set user GroupId to matching ChoreDoer GroupId.
                        user.GroupId = check.GroupId;
                    }
                }
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link

                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account");

                    ViewBag.Message = "Check your email and confirm your account, you must be confirmed "
                                      + "before you can log in.";

                    return(View("Info"));
                    // return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #4
0
        public ActionResult DeletePost(int id)
        {
            using (var context = new RotatingChoresContext())
            {
                var chore = GetChoreById(id, context);
                if (chore != null && IsGroupObject(chore.GroupId))
                {
                    context.Chores.Remove(chore);
                    context.SaveChanges();
                    TempData["Message"] = "Chore successfully deleted!";
                    return(RedirectToAction("Index"));
                }

                TempData["FailureMessage"] = "There was an issuse deleting the chore.";
                return(RedirectToAction("Index"));
            }
        }
Beispiel #5
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));
            }
        }
 public ActionResult Add(ChoreDoerModel model)
 {
     using (var context = new RotatingChoresContext())
     {
         var newDoer = context.ChoreDoers.Create();
         newDoer.GroupId = User.Identity.GetGroupId();
         model.UpdateDoer(newDoer);
         try
         {
             context.ChoreDoers.Add(newDoer);
             context.SaveChanges();
             TempData["Message"] = "New group member added!";
         }
         catch (Exception e)
         {
             TempData["FailureMessage"] = e.Message;
             return(View(model));
         }
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult Edit(ChoreDoerModel doerModel)
 {
     using (var context = new RotatingChoresContext())
     {
         var doer = doerModel.GetRepresentedDoer(context);
         if (doer != null)
         {
             var group = GetUserGroup(context);
             doerModel.AddChoresList(doer, group);
             ValidateChores(doerModel);
             if (ModelState.IsValid && IsGroupObject(doer.GroupId))
             {
                 doerModel.UpdateDoer(doer);
                 context.SaveChanges();
                 TempData["Message"] = "Chore doer profile has been updated!";
                 return(RedirectToAction("Index"));
             }
             return(View(doerModel));
         }
         return(DoerNotFound());
     }
 }
Beispiel #8
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));
            }
        }