示例#1
0
        public ActionResult Create([Bind(Include = "phonebookid,name,datecreated,datemodified,active")] PhoneBook phoneBook)
        {
            if (ModelState.IsValid)
            {
                db.PhoneBooks.Add(phoneBook);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(phoneBook));
        }
示例#2
0
        public ActionResult Create([Bind(Include = "phonebookentryid,phonebookid,name,phonenumber,datecreated,datemodified,active")] PhoneBookEntry phoneBookEntry)
        {
            if (ModelState.IsValid)
            {
                db.PhoneBookEntries.Add(phoneBookEntry);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.phonebookid = new SelectList(db.PhoneBooks, "phonebookid", "name", phoneBookEntry.phonebookid);
            return(View(phoneBookEntry));
        }
        public IHttpActionResult Put(PhoneBookEntryViewModel phoneBookEntryViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid PhoneBookEntryViewModel"));
            }

            PhoneBookEntryViewModel existingPhoneBookEntry = null;

            using (var phoneBookEntities = new CIB_PhoneBookEntities())
            {
                existingPhoneBookEntry = phoneBookEntities.PhoneBookEntries.Where(pb => pb.phonebookentryid == phoneBookEntryViewModel.phonebookentryid) as PhoneBookEntryViewModel;

                if (existingPhoneBookEntry != null)
                {
                    existingPhoneBookEntry.name         = phoneBookEntryViewModel.name;
                    existingPhoneBookEntry.phonenumber  = phoneBookEntryViewModel.phonenumber;
                    existingPhoneBookEntry.datemodified = DateTime.Now;

                    phoneBookEntities.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
        public IHttpActionResult PostNewPhoneBookEntry(PhoneBookEntryViewModel phoneBookEntry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }


            using (var pb = new CIB_PhoneBookEntities())
            {
                pb.PhoneBookEntries.Add(new PhoneBookEntry()
                {
                    phonebookid  = phoneBookEntry.phonebookid,
                    name         = phoneBookEntry.name,
                    phonenumber  = phoneBookEntry.phonenumber,
                    datecreated  = DateTime.Now,
                    datemodified = DateTime.Now,
                    active       = phoneBookEntry.active
                });

                pb.SaveChanges();
            }

            return(Ok());
        }
        public IHttpActionResult PostNewPhoneBook(PhoneBookViewModel phoneBook)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            using (var pb = new CIB_PhoneBookEntities())
            {
                pb.PhoneBooks.Add(new PhoneBook()
                {
                    name         = phoneBook.name,
                    datecreated  = DateTime.Now,
                    datemodified = DateTime.Now,
                    active       = phoneBook.active
                });

                pb.SaveChanges();
            }

            return(Ok());
        }