예제 #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));
        }
예제 #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) };
            }
        }
예제 #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;

        }
예제 #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 });
     }
 }
예제 #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) };

        }
예제 #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) };
 }
예제 #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) };
 }
예제 #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));
 }
예제 #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) };
 }
예제 #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 });
            }
        }
예제 #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) };
 }
예제 #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));
        }
예제 #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 });
            }
        }
예제 #14
0
 public ActionResult Register(Member m)
 {
     Repository.Add(m);
     // return View("RegistrationPage");
     return RedirectToAction("Register");
 }
예제 #15
0
파일: Repository.cs 프로젝트: rnmisrahi/JB
 public static void Add(Member m)
 {
     Members.Add(m);
 }
예제 #16
0
 public ActionResult Register(Member m)
 {
     Repository.Add(m);
     return RedirectToAction("Register");
 }
예제 #17
0
 public ActionResult QueryMember()
 {
     Member m = new Member();
     return View("ShowMemberPage", m);
 }
예제 #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
            }
        }
예제 #19
0
파일: Repository.cs 프로젝트: rnmisrahi/JB
 public static void Edit(Member m, Member newMember)
 {
     m.Id = newMember.Id;
     m.Name = newMember.Name;
     m.Seniority = newMember.Seniority;
 }
예제 #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));
        }
예제 #21
0
 public MemberViewModel()
 {
     MemberData = new Member();
 }