public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChapterAddress chapterAddress = db.ChapterAddresses.Find(id);

            var statedd = new SelectList(db.States.ToList(), "Id", "Name");

            ViewData["StateDD"] = statedd;
            //using viewbag
            ViewBag.statedd = new SelectList(db.States.ToList(), "Id", "Name");

            if (id != null && chapterAddress == null)
            {
                return(RedirectToAction("Create", new { id }));
            }

            if (chapterAddress == null)
            {
                return(HttpNotFound());
            }
            return(View(chapterAddress));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ChapterAddress chapterAddress = db.ChapterAddresses.Find(id);

            db.ChapterAddresses.Remove(chapterAddress);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
        private void DeleteChapterAddress(int chapterId)
        {
            var chapterAddressID = (from s in db.ChapterAddresses
                                    where s.ChapterId == chapterId
                                    select s.ChapterAddressId).FirstOrDefault();

            ChapterAddress chapterAddress = db.ChapterAddresses.Find(chapterAddressID);

            db.ChapterAddresses.Remove(chapterAddress);
            db.SaveChanges();
        }
        public ActionResult Edit([Bind(Include = "ChapterAddressId,ChapterId,StreetAddress1,StreetAddress2,City,StateId,Zip,Active,DateModified,DateCreated")] ChapterAddress chapterAddress)
        {
            chapterAddress.DateModified = System.DateTime.Now;
            chapterAddress.DateCreated  = chapterAddress.DateCreated;

            if (ModelState.IsValid)
            {
                db.Entry(chapterAddress).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", "Chapters"));
            }
            return(View(chapterAddress));
        }
        // GET: ChapterAddresses/Details/5
        //[Authorize]
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChapterAddress chapterAddress = db.ChapterAddresses.Find(id);

            if (chapterAddress == null)
            {
                return(HttpNotFound());
            }
            return(View(chapterAddress));
        }
        public ActionResult Create([Bind(Include = "ChapterAddressId,ChapterId,StreetAddress1,StreetAddress2,City,StateId,Zip,Active,DateModified,DateCreated")] ChapterAddress chapterAddress)
        {
            chapterAddress.DateModified = System.DateTime.Now;
            chapterAddress.DateCreated  = System.DateTime.Now;

            var chapterId = Request.Form["ChapterId"].ToString();

            chapterAddress.ChapterId = int.Parse(chapterId);

            if (ModelState.IsValid)
            {
                db.ChapterAddresses.Add(chapterAddress);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(chapterAddress));
        }