public void UpdateSupplier(UpdateSupplierModel updatedSupplier) { var collection = database.GetCollection <SupplierModelView>("Supplier"); var filter = Builders <SupplierModelView> .Filter.Eq("SupplierID", updatedSupplier.SupplierID); var result = collection.ReplaceOne(filter, updatedSupplier.updatedRecord); }
// Put api/<controller> public JsonResponse Put([FromBody] UpdateSupplierModel updatedSupplier) { try { _context.UpdateSupplier(updatedSupplier); return(new JsonResponse(1, "", null)); } catch (Exception ex) { return(new JsonResponse(-1, ex.Message, null)); } }
public ActionResult UpdateSupplier(UpdateSupplierModel model) { bool updatedSupplier; string errorMessage; Supplier formSupplierData = null; try { if (model.IsValid(out errorMessage)) { using (ProductListContext productContext = new ProductListContext()) { // update the supplier productContext.UpdateSupplier(model.SupplierID, model.Name, model.PhoneNumber); productContext.SaveChanges(); } updatedSupplier = true; } else { // save form data for when we return formSupplierData = new Supplier { SupplierID = model.SupplierID, Name = model.Name, PhoneNumber = model.PhoneNumber }; updatedSupplier = false; } } catch (Exception e) { updatedSupplier = false; errorMessage = Errors.GenericMVCInternalError; ErrorLog.LogError(e); } ActionResult result; if (updatedSupplier) { // Updated product, return to list ProductListModel viewModel = new ProductListModel { AddedOrUpdatedProduct = true }; result = RedirectToAction("Index", viewModel); } else { // Error, show message AddUpdateSupplierViewModel viewModel = AddUpdateSupplierViewModel.GetModel(formSupplierData, errorMessage); result = View("AddUpdateSupplier", viewModel); } return(result); }
public async Task <ActionResult <object> > UpdateAsync([FromBody] UpdateSupplierModel model) { return(await _supplier.UpdateAsync(model)); }