コード例 #1
0
        //Get: Speaker/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service = CreateSpeakerService();
            var details = service.GetSpeakerById(id);
            var model
                = new SpeakerEdit
                {
                SpeakerId    = details.SpeakerId,
                SpeakerFName = details.SpeakerFName,
                SpeakerLName = details.SpeakerLName,
                State        = details.State,
                Address      = details.Address,
                City         = details.City
                };

            return(View(model));
        }
コード例 #2
0
        public bool EditSpeaker(SpeakerEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity
                    = ctx
                      .Speakers
                      .Single(e => e.SpeakerId == model.SpeakerId && e.OwnerId == _userid);

                entity.SpeakerId    = model.SpeakerId;
                entity.SpeakerFName = model.SpeakerFName;
                entity.SpeakerLName = model.SpeakerLName;
                entity.Address      = model.Address;
                entity.City         = model.City;
                entity.State        = model.State;
                entity.ModifiedUtc  = DateTimeOffset.Now;

                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #3
0
        public ActionResult Edit(int id, SpeakerEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateSpeakerService();

            if (model.SpeakerId != id)
            {
                ModelState.AddModelError("", "Id mismatch");
            }

            if (service.EditSpeaker(model))
            {
                TempData["SaveResult"] = "Speaker was successfully updated";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Speaker could not be updated");
            return(View(model));
        }