コード例 #1
0
        public ActionResult DeleteConfirmed(detailsEventViewModel model)
        {
            var @event = db.Events.FirstOrDefault(x => x.Id == model.Id);

            if (ModelState.IsValid)
            {
                @event.Title = model.Title;
                @event.StartDate = model.StartDate;
                @event.Description = model.Description;
                @event.Address.Street = model.Street;
                @event.Address.City = model.City;
                @event.Address.State = model.State;
                @event.Address.ZipCode = model.ZipCode;

                if (User.Identity.GetUserId() == @event.ApplicationUserId)
                {
                    db.Entry(@event).State = EntityState.Deleted;
                    db.SaveChanges();

                    // create message telling user changes have been saved
                }
                else
                {
                    ViewBag.noDelete = "Only the event organizer can delete the event.";
                }
            }

            return RedirectToAction("home", "Dashboard", "Dashboard");
        }
コード例 #2
0
        // GET: Events/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var @event = db.Events.Include(x => x.Address).SingleOrDefault(x => x.Id == id.Value);

            if (@event == null)
            {
                return HttpNotFound();
            }

            var myViewModel = new detailsEventViewModel
            {
                Id = @event.Id,
                StartDate = @event.StartDate,
                Title = @event.Title,
                Description = @event.Description,
                ApplicationUserId = User.Identity.GetUserId(),
                AddressId = @event.Address.Id,
                Street = @event.Address.Street,
                City = @event.Address.City,
                State = @event.Address.State,
                ZipCode = @event.Address.ZipCode
            };

            return View(myViewModel);
        }