public bool UpdateCooperator(CooperatorEdit model, Guid userId)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Cooperators.Single(e => e.CooperatorId == model.CooperatorId && e.OwnerId == userId);

                entity.FirstName    = model.FirstName;
                entity.LastName     = model.LastName;
                entity.Phone        = model.Phone;
                entity.Email        = model.Email;
                entity.OwnerId      = model.OwnerId;
                entity.ContactType  = model.ContactType;
                entity.CooperatorId = model.CooperatorId;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemple #2
0
        public ActionResult Edit(int id)
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new CooperatorService(userId);
            var detail  = service.GetCooperatorById(id, userId);
            var model   = new CooperatorEdit
            {
                CooperatorId = detail.CooperatorId,
                FirstName    = detail.FirstName,
                LastName     = detail.LastName,
                Phone        = detail.Phone,
                Email        = detail.Email,
                ContactType  = detail.ContactType,
                OwnerId      = detail.OwnerId
            };

            return(View(model));
        }
Exemple #3
0
        public ActionResult Edit(int id, CooperatorEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.CooperatorId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new CooperatorService(userId);

            if (service.UpdateCooperator(model, userId))
            {
                TempData["SaveResult"] = "Your cooperator was updated.";
                return(RedirectToAction("Index"));
            }

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