示例#1
0
 public ActionResult Register()
 {
     EditMemberViewModel rvm = new EditMemberViewModel
     {
         MemberData=new Member(),
         Cities = CityRepository.Cities
     };
     
     return View(rvm);
 }
示例#2
0
        //public static List<EditMemberViewModel> CreateEditViewModel_prev()
        //{
        //    List<EditMemberViewModel> emvms = new List<EditMemberViewModel>();
        //    foreach (Member member in Repository.Members)
        //    {
        //        EditMemberViewModel emvm = new EditMemberViewModel();
        //        emvm.MemberData = member;
        //        emvm.Cities = CityRepository.Cities;
        //        emvms.Add(emvm);
        //    }
        //    return emvms;
        //}

        public static EditMemberViewModel CreateEditViewModel(int id)
        {
            Member member = Repository.Members.FirstOrDefault(m => m.Id == id);
            if (member != null)
            {
                EditMemberViewModel emvm = new EditMemberViewModel();
                emvm.MemberData = member;
                emvm.Cities = CityRepository.Cities;
                return emvm;
            }
            else
            {
                return null;
            }
        }
示例#3
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));
        }
示例#4
0
 public ActionResult Create(EditMemberViewModel m)
 {
     Repository.Add(m.MemberData);
     return View(m);
 }