Exemple #1
0
        public ActionResult Save(Reader reader)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new ReaderFormModel
                {
                    Reader          = reader,
                    MembershipTypes = _context.MembershipTypes.ToList()
                };

                return(View("ReaderForm", viewModel));
            }

            if (reader.Id == 0)
            {
                _context.Readers.Add(reader);
            }
            else
            {
                var readerInDb = _context.Readers.Single(r => r.Id == reader.Id);
                readerInDb.Name             = reader.Name;
                readerInDb.Birth            = reader.Birth;
                readerInDb.MembershipTypeId = reader.MembershipTypeId;
                readerInDb.IsSubcribe       = reader.IsSubcribe;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Readers"));
        }
Exemple #2
0
        //-------READERFORM------------------
        public ActionResult ReaderForm()
        {
            var membershipTypes = _context.MembershipTypes.ToList();

            var viewModel = new ReaderFormModel
            {
                MembershipTypes = membershipTypes
            };

            return(View("ReaderForm", viewModel));
        }
Exemple #3
0
        //------EDIT--------------
        public ActionResult Edit(int id)
        {
            var reader = _context.Readers.SingleOrDefault(r => r.Id == id);

            if (reader == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new ReaderFormModel
            {
                Reader          = reader,
                MembershipTypes = _context.MembershipTypes.ToList()
            };

            return(View("ReaderForm", viewModel));
        }