public ActionResult Create(PrivateKeyCreateViewModel viewModel) { try { if (ModelState.IsValid) { using (var context = dataContextFactory.CreateByUser()) { var privateKey = new Model.PrivateKey(); privateKey.SetKeyBytes(); privateKey.DisplayName = viewModel.DisplayName; privateKey.Vendor = context.Vendors.Single(v => v.ObjectId == viewModel.VendorId); context.PrivateKeys.Add(privateKey); context.SaveChanges(); } return(RedirectToAction("Details", "Vendor", new { key = viewModel.VendorId })); } else { return(View(viewModel)); } } catch { throw; } }
/// <summary> /// Create a single privateKey /// </summary> /// <param name="parentVendor">GUID of assiciated vendor</param> /// <returns>Create privateKey view</returns> public ActionResult Create(Guid parentVendor) { using (var context = dataContextFactory.CreateByUser()) { var vendorQuery = from x in context.Vendors where x.ObjectId == parentVendor select x; PrivateKeyCreateViewModel viewModel = new PrivateKeyCreateViewModel(vendorQuery.FirstOrDefault()); return(View(viewModel)); } }