예제 #1
0
        public ActionResult AgentEdit(int id)
        {
            var svc    = new AgentService();
            var detail = svc.GetAgentByID(id);
            var model  =
                new AgentEdit
            {
                AgentID       = detail.AgentID,
                LicenseNumber = detail.LicenseNumber,
                Name          = detail.Name,
                Email         = detail.Email,
                Address       = detail.Address,
                PhoneNumber   = detail.PhoneNumber
            };

            return(View(model));
        }
예제 #2
0
        public bool UpdateAgent(AgentEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Agents
                    .Single(e => e.AgentID == model.AgentID);
                entity.LicenseNumber = model.LicenseNumber;
                entity.Name          = model.Name;
                entity.Email         = model.Email;
                entity.Address       = model.Email;
                entity.PhoneNumber   = model.PhoneNumber;

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #3
0
        public ActionResult AgentEdit(int id, AgentEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.AgentID != id)
            {
                ModelState.AddModelError("", "ID Mismatch");
                return(View(model));
            }

            var svc = new AgentService();

            if (svc.UpdateAgent(model))
            {
                TempData["SaveResult"] = "The Agent was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "The agent could not be updated");
            return(View(model));
        }