public ActionResult Edit(VendorCredentialModel inputModel) { if (!ModelState.IsValid) { var resultModel = VendorCredentialModel.ForEdit(dataContextFactory, inputModel.VendorCredentialId.Value); resultModel.CredentialName = inputModel.CredentialName; resultModel.CredentialValue = inputModel.CredentialValue; return(View("CreateEdit", resultModel)); } using (var dataContext = dataContextFactory.Create()) { var vendorCredential = dataContext.VendorCredentials.Where(x => x.VendorCredentialId == inputModel.VendorCredentialId.Value).Single(); vendorCredential.CredentialName = inputModel.CredentialName; vendorCredential.CredentialValue = SymmetricEncryption.EncryptForDatabase(Encoding.UTF8.GetBytes(inputModel.CredentialValue)); dataContext.SaveChanges(); } Flash.Success("VendorCredential was successfully modified."); return(RedirectToAction("Details", "Vendor", new { key = inputModel.VendorId })); }
public ActionResult Create(VendorCredentialModel inputModel) { if (!ModelState.IsValid) { var resultModel = VendorCredentialModel.ForCreate(dataContextFactory, inputModel.VendorId); resultModel.CredentialName = inputModel.CredentialName; resultModel.CredentialValue = inputModel.CredentialValue; return(View("CreateEdit", resultModel)); } using (var dataContext = dataContextFactory.Create()) { var vendor = dataContext.Vendors.Single(v => v.ObjectId == inputModel.VendorId); // ensuring the vendor is authorized dataContext.VendorCredentials.Add(new VendorCredential() { Vendor = vendor, CredentialName = inputModel.CredentialName, CredentialValue = SymmetricEncryption.EncryptForDatabase(Encoding.UTF8.GetBytes(inputModel.CredentialValue)) }); dataContext.SaveChanges(); } Flash.Success("VendorCredential was successfully saved."); return(RedirectToAction("Details", "Vendor", new { key = inputModel.VendorId })); }
public ActionResult Remove(Guid VendorId, Guid VendorCredentialId) { if (!ModelState.IsValid) { var resultModel = VendorCredentialModel.ForEdit(dataContextFactory, VendorCredentialId); return(View("Remove", resultModel)); } using (var dataContext = dataContextFactory.Create()) { dataContext.VendorCredentials.Remove(s => s.VendorCredentialId == VendorCredentialId); dataContext.SaveChanges(); } Flash.Success("VendorCredential was successfully deleted."); return(RedirectToAction("Details", "Vendor", new { key = VendorId })); }
public ActionResult Remove(Guid key) { var model = VendorCredentialModel.ForEdit(dataContextFactory, key); return(View("Remove", model)); }
public ActionResult Create(Guid parentVendor) { var model = VendorCredentialModel.ForCreate(dataContextFactory, parentVendor); return(View("CreateEdit", model)); }