// // GET: /Consumer/Create public ActionResult Create() { Consumer consumer = new Consumer(); consumer.Key = Guid.NewGuid().ToString("N").Substring(0, 16); consumer.Secret = Guid.NewGuid().ToString("N").Substring(0, 16); return View(consumer); }
public ActionResult Create(Consumer consumer) { if (ModelState.IsValid) { // Make sure the user did not create a non-unique key var match = ProviderContext.Consumers.SingleOrDefault( c => c.Key == consumer.Key); if (match != null) { ModelState.AddModelError("Key", UniqueKeyErrorMessage); } else { ProviderContext.Consumers.Add(consumer); ProviderContext.SaveChanges(); if (string.IsNullOrEmpty(Request["ReturnURL"])) { return RedirectToAction("Index"); } var uri = new UriBuilder(Request["ReturnURL"]); uri.Query += "ConsumerId=" + consumer.ConsumerId; return Redirect(uri.ToString()); } } return View(consumer); }
public ActionResult Edit(Consumer consumer) { if (ModelState.IsValid) { // Make sure the user did not change the Key to // a non-unique value var match = ProviderContext.Consumers.SingleOrDefault( c => c.Key == consumer.Key && c.ConsumerId != consumer.ConsumerId); if (match != null) { ModelState.AddModelError("Key", UniqueKeyErrorMessage); } else { ProviderContext.Entry(consumer).State = EntityState.Modified; ProviderContext.SaveChanges(); return RedirectToAction("Index"); } } return View(consumer); }