public ActionResult LeadSourceEdit(int id, LeadSourceEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new LeadSourceService(userId);

            if (service.UpdateLeadSource(model))
            {
                TempData["SaveResult"] = "Your Source was updated.";
                return(RedirectToAction("LeadSourceIndex"));
            }

            ModelState.AddModelError("", "Your Source could not be updated.");
            return(View(model));
        }
        public bool UpdateLeadSource(LeadSourceEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .SourceTypes
                    .Single(e => e.SourceTypeID == model.SourceTypeID && e.OwnerId == _userId);

                entity.Source      = model.Source;
                entity.Description = model.Description;
                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult LeadSourceEdit(int id)
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new LeadSourceService(userId);
            var detail  = service.GetLeadSourceById(id);
            var model   =
                new LeadSourceEdit
            {
                SourceTypeID = detail.SourceTypeID,
                Source       = detail.Source,
                Description  = detail.Description
            };

            return(View(model));
        }