Exemple #1
0
 public ActionResult Delete(int id)
 {
     Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == id);
     if (currentMember != null)
     {
         Random rnd = new Random();
         int first = rnd.Next(1, 9);
         int second = rnd.Next(1, 9);
         DeleteMemberViewModel delVm = new DeleteMemberViewModel
         {
             MemberData = currentMember,
             RightAnswer = first + second,
             Exercise = first.ToString() + " + " + second.ToString(),
         };
         return View(delVm);
     }
     else
         return View("ErrorPage", string.Format("{0} not found", id));
 }
Exemple #2
0
        public ActionResult Delete(DeleteMemberViewModel member) 
        {
            Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.MemberData.Id);
            if (currentMember != null)
            {
                if (member.UserAnswer != member.RightAnswer)
                {
                    ModelState.AddModelError("UserAnswer", "You must enter the correct answer");
                }

                if (ModelState.IsValid)
                {
                    Repository.Members.Remove(currentMember);
                    return RedirectToAction("Index");
                }
                else
                {
                    return View(member);
                }
            }
            else
                return View("ErrorPage", string.Format("{0} not found", member.MemberData.Id));
        }