Пример #1
0
        public ActionResult Save(Member member)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new MemberViewFormModel {
                    Member          = member,
                    MembershipTypes = _context.MembershipTypes.ToList()
                };

                ViewBag.Message = member.Id == 0 ? "Create Member" : "Edit Member";
                return(View("MemberForm", viewModel));
            }

            if (member.Id == 0)
            {
                _context.Members.Add(member);
            }
            else
            {
                var memberInDb = _context.Members.Single(m => m.Id == member.Id);

                memberInDb.Name                     = member.Name;
                memberInDb.BirthDate                = member.BirthDate;
                memberInDb.MembershipTypeId         = member.MembershipTypeId;
                memberInDb.IsSubscribedToNewsletter = member.IsSubscribedToNewsletter;
            }
            _context.SaveChanges();
            return(RedirectToAction("Index", "Members"));
        }
Пример #2
0
        public ActionResult New()
        {
            var membershipTypes = _context.MembershipTypes.ToList();
            var viewModel       = new MemberViewFormModel {
                Member          = new Member(),
                MembershipTypes = membershipTypes
            };

            ViewBag.Message = "Create Member";
            return(View("MemberForm", viewModel));
        }
Пример #3
0
        public ActionResult Edit(int id)
        {
            var member = _context.Members.SingleOrDefault(m => m.Id == id);

            if (member == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new MemberViewFormModel {
                Member          = member,
                MembershipTypes = _context.MembershipTypes.ToList()
            };

            ViewBag.Message = "Edit Member";
            return(View("MemberForm", viewModel));
        }