public ActionResult Register(AgileCrmModel model) { ModelState.Remove("Id"); if (ModelState.IsValid) { using (var ctx = new SynergyDbContext()) { string ApiName = ApiTypes.AgileCrm.ToString(); var api = ctx.Synergy_API.Where(x => x.Api == ApiName).FirstOrDefault(); Synergy_ApiConfiguration configuration = new Synergy_ApiConfiguration() { ApiId = api.Id, Email = model.Email, Key = model.Key, Url = model.Url, UserId = Convert.ToInt32(User.Identity.Name), IsActive = true }; ctx.Synergy_ApiConfigurations.Add(configuration); ctx.SaveChanges(); } return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Update(int id) { AgileCrmModel model = null; using (var ctx = new SynergyDbContext()) { model = ctx.Synergy_ApiConfigurations. Where(x => x.Id == id && x.IsActive). Select(x => new AgileCrmModel() { Id = x.Id, Key = x.Key, Url = x.Url, Email = x.Email }).FirstOrDefault(); } return(View(model)); }
public ActionResult Update(AgileCrmModel model) { if (ModelState.IsValid) { using (var ctx = new SynergyDbContext()) { var configuration = ctx.Synergy_ApiConfigurations. Where(x => x.Id == model.Id && x.IsActive).FirstOrDefault(); if (configuration != null) { configuration.Key = model.Key; configuration.Email = model.Email; configuration.Url = model.Url; } ctx.SaveChanges(); } return(RedirectToAction("Index")); } return(View(model)); }