Beispiel #1
0
        public ActionResult Edit(Member member)
        {
            Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id);
            if (currentMember != null)
            {
                if (DateTime.Today.Year - member.BirthDate.Year - member.Seniority < 14)
                {
                    ModelState.AddModelError("Seniority", "We count your seniority from age of 14 only");
                }

                if (ModelState.IsValid)
                {
                    currentMember.Name = member.Name;
                    currentMember.Seniority = member.Seniority;
                    currentMember.IsProgrammer = member.IsProgrammer;
                    currentMember.CityId = member.CityId;
                    currentMember.BirthDate = member.BirthDate;
                    currentMember.IsAcceptConditions = member.IsAcceptConditions;
                    return RedirectToAction("Index");
                }
                else
                {
                    return View(new EditMemberViewModel {MemberData = member, Cities = CityRepository.Cities});
                }
            }
            else
                return View("ErrorPage", string.Format("{0} not found", member.Id));
        }
Beispiel #2
0
        public ActionResult Edit(Member member)
        {
            try
            {
                if ((member != null) && (member.Id != null))
                {
                    Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id);
                    if (currentMember != null)
                    {
                        if (member.Id != member.newId) //The Id changed
                        {
                            currentMember.Id = member.newId;
                        }

                        currentMember.Name = member.Name;
                        currentMember.Seniority = member.Seniority;
                        currentMember.IsAProgrammer = member.IsAProgrammer;
                        return RedirectToAction("Index");
                    }
                }
                throw new Exception(String.Format("{0} Not found", member.Id));
            }
            catch (Exception ex)
            {
                return new ContentResult { Content = string.Format("Error: {0}", ex.Message) };
            }
        }
Beispiel #3
0
        public static ValidationResult IsValid_BirthDate_Seniority(Member member)
        {
            if (DateTime.Today.Year - member.BirthDate.Year - member.Seniority < 14)
            {
                return new ValidationResult("We count your seniority from age of 14 only");
            }
            return null;

        }
Beispiel #4
0
 public ActionResult Register(Member member)
 {
     if (ModelState.IsValid)
     {
         Repository.Add(member);
         return RedirectToAction("Index");
     }
     else
     {
         return View(new EditMemberViewModel { MemberData = member, Cities = CityRepository.Cities });
     }
 }
Beispiel #5
0
        public ActionResult Delete(Member member) 
        {
            Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id);
            if (currentMember != null)
            {
                Repository.Members.Remove(currentMember);
                return RedirectToAction("Index");
            }
            else
                return new ContentResult { Content = string.Format("{0} not found", member.Id) };

        }
Beispiel #6
0
 public ActionResult Edit(Member member)
 {
     Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id);
     if (member != null)
     {
         currentMember.Name = member.Name;
         currentMember.Seniority = member.Seniority;
         return RedirectToAction("Index");
     }
     else
         return new ContentResult { Content = string.Format("{0} not found", member.Id) };
 }
Beispiel #7
0
 public ActionResult SaveMember(Member editedMember)
 {
     Member member = Repository.Members.FirstOrDefault(m => m.Id == editedMember.Id);
     if (member != null)
     {
         member.Name = editedMember.Name;
         member.Seniority = editedMember.Seniority;
         return RedirectToAction("Index");
     }
     else
         return new ContentResult { Content = string.Format("{0} not found", editedMember.Id) };
 }
Beispiel #8
0
 public ActionResult Edit(Member member)
 {
     Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id);
     if (member != null)
     {
         currentMember.Name = member.Name;
         currentMember.Seniority = member.Seniority;
         currentMember.IsProgrammer = member.IsProgrammer;
         currentMember.CityId = member.CityId;
         return RedirectToAction("Index");
     }
     else
         return View("ErrorPage", string.Format("{0} not found", member.Id));
 }
Beispiel #9
0
 public ActionResult Edit(Member member, int prevId)
 {
     Debug.WriteLine("Query String: {0}", Request.QueryString);
     Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == prevId);
     if (member != null)
     {
         currentMember.Id = member.Id;
         currentMember.Name = member.Name;
         currentMember.Seniority = member.Seniority;
         return RedirectToAction("Index");
     }
     else
         return new ContentResult { Content = string.Format("{0} not found", prevId) };
 }
Beispiel #10
0
        public ActionResult Register(Member member)
        {
            if (DateTime.Today.Year - member.BirthDate.Year - member.Seniority < 14)
            {
                ModelState.AddModelError("Seniority", "We count your seniority from age of 14 only");
            }

            if (ModelState.IsValid)
            {
                Repository.Add(member);
                return RedirectToAction("Index");
            }
            else
            {
                return View(new EditMemberViewModel { MemberData = member, Cities = CityRepository.Cities });
            }
        }
Beispiel #11
0
 public ActionResult Edit(Member member)
 {
     Member memberFound = Repository.Members.FirstOrDefault(m => m.Id == member.Id);
     if (memberFound != null)
     {
         if (member.action.Equals("Edit"))
             return View(memberFound);
         else //It contains info already
         {
             memberFound.Name = member.Name;
             memberFound.Seniority = member.Seniority;
             memberFound.IsProgrammer = member.IsProgrammer;
             return RedirectToAction("Index");
         }
     }
     else
         return View("ErrorPage", string.Format("{0} not found", member.Id));
         // return new ContentResult { Content = string.Format("{0} not found", id) };
 }
Beispiel #12
0
        public ActionResult Edit(Member member)
        {
            Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id);
            if (currentMember != null)
            {
                //if (member.Id < 100 || member.Id > 9999)
                //    ModelState.AddModelError("Id", "Id value must be 100-9999");
                if (member.Name.Length < 3)
                    ModelState.AddModelError("Name", "Minimum name length is 3 characters");
                if (member.Name.Length > 12)
                    ModelState.AddModelError("Name", "Maximum name length is 12 characters");
                if (member.Seniority < 0 || member.Seniority > 50)
                    ModelState.AddModelError("Seniority", "Seniority 0-50");
                if (Underage(member.BirthDate, 18))
                    ModelState.AddModelError("BirthDate", "You are under 18 kid. Sorry, no can do.");
                if (Overage(member.BirthDate, 100))
                    ModelState.AddModelError("BirthDate", "You are an old fart. Sorry, no can do.");

                if (ModelState.IsValid)
                {
                    currentMember.Name = member.Name;
                    currentMember.Seniority = member.Seniority;
                    currentMember.IsProgrammer = member.IsProgrammer;
                    currentMember.CityId = member.CityId;
                    currentMember.BirthDate = member.BirthDate;
                    currentMember.IsAcceptConditions = member.IsAcceptConditions;
                    return RedirectToAction("Index");
                }
                else
                {
                    EditMemberViewModel emvm = new EditMemberViewModel
                    {
                        MemberData=member,
                        Cities=CityRepository.Cities,
                    };
                    return View(emvm);
                }
            }
            else
                return View("ErrorPage", string.Format("{0} not found", member.Id));
        }
Beispiel #13
0
        public ActionResult Register(Member member)
        {
            if (member.Name.Length < 2 || member.Name.Length > 12)
            {
                ModelState.AddModelError("Name", "Name: 2-12 characters");
            }
            if (DateTime.Today.Year - member.BirthDate.Year < 18)
            {
                ModelState.AddModelError("BirthDate", "You are too young. Try tomorrow.");
            }
            else if (DateTime.Today.Year - member.BirthDate.Year > 100)
            {
                ModelState.AddModelError("BirthDate", "You are too old. Have you great-grandsons?");
            }
            if (DateTime.Today.Year - member.BirthDate.Year - member.Seniority < 14)
            {
                ModelState.AddModelError("Seniority", "We count your seniority from age of 14 only");
            }
            if (member.CityId == -1)
            {
                ModelState.AddModelError("CityId", "You must select a city");
            }
            if (!member.IsAcceptConditions && !(!member.IsProgrammer && member.CityId == 7000))
            {
                ModelState.AddModelError("IsAcceptConditions", "You must accept our conditions");
            }

            if (ModelState.IsValid)
            {
                Repository.Add(member);
                return RedirectToAction("Index");
            }
            else
            {
                return View(new EditMemberViewModel { MemberData = member, Cities = CityRepository.Cities });
            }
        }
Beispiel #14
0
 public ActionResult Register(Member m)
 {
     Repository.Add(m);
     // return View("RegistrationPage");
     return RedirectToAction("Register");
 }
Beispiel #15
0
 public static void Add(Member m)
 {
     Members.Add(m);
 }
Beispiel #16
0
 public ActionResult Register(Member m)
 {
     Repository.Add(m);
     return RedirectToAction("Register");
 }
Beispiel #17
0
 public ActionResult QueryMember()
 {
     Member m = new Member();
     return View("ShowMemberPage", m);
 }
Beispiel #18
0
        //public ActionResult Edit(int id)
        //{
        //    Member member = Repository.Members.FirstOrDefault(m => m.Id == id);
        //    if (member != null)
        //    {
        //        return View(member);
        //    }
        //    else
        //        return View("ErrorPage", string.Format("{0} not found", id));
        //}

        //[HttpPost]
        //public ActionResult Edit(Member member)
        //{
        //    Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id);
        //    if (member != null)
        //    {
        //        currentMember.Name = member.Name;
        //        currentMember.Seniority = member.Seniority;
        //        currentMember.IsProgrammer = member.IsProgrammer;
        //        return RedirectToAction("Index");
        //    }
        //    else
        //        return View("ErrorPage", string.Format("{0} not found", member.Id));
        //}

        public ActionResult Edit()
        {
            if (Request.HttpMethod == "GET")
            {
                #region GET Code
                #region Get id
                int id;
                if (Request["id"] != null)
                {
                    id = int.Parse(Request["id"]);
                }
                else
                {
                    string[] UrlParts = Request.RawUrl.Split('/');
                    id = int.Parse(UrlParts[UrlParts.Length - 1]);
                }
                #endregion
                #region Get member
                Member member = Repository.Members.FirstOrDefault(m => m.Id == id);
                if (member != null)
                {
                    return View(member);
                }
                else
                    return View("ErrorPage", string.Format("{0} not found", id));
                
                #endregion
                #endregion
            }
            else
            {
                #region POST Code
                #region Binding
                Member member = new Member
                {
                    Id=int.Parse(Request["id"]),
                    Name=Request["Name"],
                    Seniority = int.Parse(Request["Seniority"]),
                    IsProgrammer=bool.Parse(Request["IsProgrammer"].Split(',')[0]),
                };
                #endregion
                #region Update
                Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id);
                if (currentMember != null)
                {
                    currentMember.Name = member.Name;
                    currentMember.Seniority = member.Seniority;
                    currentMember.IsProgrammer = member.IsProgrammer;
                    return RedirectToAction("Index");
                }
                else
                    return View("ErrorPage", string.Format("{0} not found", member.Id));
                #endregion
                #endregion
            }
        }
Beispiel #19
0
 public static void Edit(Member m, Member newMember)
 {
     m.Id = newMember.Id;
     m.Name = newMember.Name;
     m.Seniority = newMember.Seniority;
 }
Beispiel #20
0
        public ActionResult Edit(Member member)
        {
            Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id);
            if (member != null)
            {
                if (member.Name==null || member.Name.Length < 2 || member.Name.Length > 12)
                {
                    ModelState.AddModelError("Name", "Name: 2-12 characters" );
                }
                if (DateTime.Today.Year - member.BirthDate.Year < 18)
                {
                    ModelState.AddModelError("BirthDate", "You are too young. Try tomorrow.");
                }
                else if (DateTime.Today.Year - member.BirthDate.Year > 100)
                {
                    ModelState.AddModelError("BirthDate", "You are too old. Have you great-grandsons?");
                }
                if (DateTime.Today.Year - member.BirthDate.Year - member.Seniority < 14)
                {
                    ModelState.AddModelError("Seniority", "We count your seniority from age of 14 only");
                }
                if (member.CityId == -1)
                {
                    ModelState.AddModelError("CityId", "You must select a city");
                }
                if (!member.IsAcceptConditions && !(!member.IsProgrammer && member.CityId==7000))
                {
                    ModelState.AddModelError("IsAcceptConditions", "You must accept our conditions");
                }

                if (ModelState.IsValid)
                {
                    currentMember.Name = member.Name;
                    currentMember.Seniority = member.Seniority;
                    currentMember.IsProgrammer = member.IsProgrammer;
                    currentMember.CityId = member.CityId;
                    currentMember.BirthDate = member.BirthDate;
                    currentMember.IsAcceptConditions = member.IsAcceptConditions;
                    return RedirectToAction("Index");
                }
                else
                {
                    return View(new EditMemberViewModel {MemberData = member, Cities = CityRepository.Cities});
                }
            }
            else
                return View("ErrorPage", string.Format("{0} not found", member.Id));
        }
Beispiel #21
0
 public MemberViewModel()
 {
     MemberData = new Member();
 }