public ActionResult AddShipment(ShipmentVM viewModel) { ActionResult oResponse = null; if (Session["UserName"] != null && (int)Session["UserLevel"] <= 2) { if (ModelState.IsValid) { try { IShipmentInfoDO shipmentform = ShipmentMap.MapPOtoDO(viewModel.Shipment); //call to method in DAL to view shipment by producerID _ShipmentAccess.InsertShipment(shipmentform); } catch (Exception e) { if (e.Message.Contains("duplicate")) { viewModel.ErrorMessage = String.Format("There is already a {0} in the database.", viewModel.Shipment.ShipmentID); } else { viewModel.ErrorMessage = "We apologize but we were unable to handle your request at this time."; } } finally { //nothing to do here } if (viewModel.ErrorMessage == null) { oResponse = RedirectToAction("ViewShipments", "Shipment"); } else { //Data call here to re-get the locations and producers. viewModel.Shipment.ProducerDDL = PopulateProducersDDL(); viewModel.Shipment.LocationDDL = PopulateLocationsDDL(); oResponse = View(viewModel); } } else { //Data call here to re-get the locations and producers. //placed into method viewModel.Shipment.ProducerDDL = PopulateProducersDDL(); viewModel.Shipment.LocationDDL = PopulateLocationsDDL(); oResponse = View(viewModel); } } else { oResponse = RedirectToAction("Login", "User"); } return(oResponse); }
public static IShipmentInfoBO MapDOtoBO(IShipmentInfoDO iFrom) { IShipmentInfoBO newshipment = new ShipmentBO(); newshipment.ShipmentID = iFrom.ShipmentID; newshipment.LocationID = iFrom.LocationID; newshipment.Product = iFrom.Product; newshipment.ProducerID = iFrom.ProducerID; newshipment.QuantityInBu = iFrom.QuantityInBu; newshipment.PricePerBushel = iFrom.PricePerBushel; return(newshipment); }
public ActionResult UpdateShipment(ShipmentVM changeshipment) { ActionResult oResult = null; if (Session["UserName"] != null && (int)Session["UserLevel"] <= 2) { if (ModelState.IsValid) { try { IShipmentInfoDO updateShipment = ShipmentMap.MapPOtoDO(changeshipment.Shipment); //call method from DAL to change the info in db _ShipmentAccess.UpdateShipment(updateShipment); } catch (Exception e) { //what to do with exception what to write if (e.Message.Contains("duplicate")) { changeshipment.ErrorMessage = "Unable to process request, duplicate record already exists"; } else { changeshipment.ErrorMessage = "We apologize but we were unable to handle your request at this time."; } } finally { } if (changeshipment.ErrorMessage == null) { //if no errors with update, return to list of shipments to see if info was changed oResult = RedirectToAction("ViewShipments", "Shipment"); } else { oResult = RedirectToAction("UpdateShipment", "Shipment"); } } else { oResult = View(changeshipment); } } else { oResult = RedirectToAction("Login", "User"); } return(oResult); }
public void InsertShipment(IShipmentInfoDO shipment) { try { //create connection to db by way of saved connection string using (SqlConnection connectionToSQL = new SqlConnection(connectionString)) //create a command to use for this data session using (SqlCommand command = new SqlCommand("ADD_SHIPMENT", connectionToSQL)) { try { //this command will call a stored proc command.CommandType = CommandType.StoredProcedure; //try for 35 seconds before error is thrown command.CommandTimeout = 35; //stored proc is set to recieve the @values below, object.value is the actual info going to SQL command.Parameters.AddWithValue("@LocationID", shipment.LocationID); command.Parameters.AddWithValue("@Product", shipment.Product); command.Parameters.AddWithValue("@ProducerID", shipment.ProducerID); command.Parameters.AddWithValue("@QuantityInBu", shipment.QuantityInBu); command.Parameters.AddWithValue("@PricePerBushel", shipment.PricePerBushel); //sql commands to open the connection and execute the stored proc, "non query" means no data needed in return connectionToSQL.Open(); command.ExecuteNonQuery(); } catch (Exception e) { //pass error out and then to presentation layer so that it can be displayed to user throw (e); } finally { //should be handles by using statements, this is back-up connectionToSQL.Close(); connectionToSQL.Dispose(); } } } catch (Exception e) { //this would be connection error, write to file and pass to presentation layer ErrorLogging.LogError(e); throw (e); } finally { //no connection to dispose, do nothing } }
public void InsertShipment(IShipmentInfoDO shipment) { try { //create connection using (SqlConnection connectionToSQL = new SqlConnection(connectionString)) //create a command using (SqlCommand command = new SqlCommand("ADD_SHIPMENT", connectionToSQL)) { try { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 35; command.Parameters.AddWithValue("@LocationID", shipment.LocationID); command.Parameters.AddWithValue("@Product", shipment.Product); command.Parameters.AddWithValue("@ProducerID", shipment.ProducerID); command.Parameters.AddWithValue("@QuantityInBu", shipment.QuantityInBu); command.Parameters.AddWithValue("@PricePerBushel", shipment.PricePerBushel); connectionToSQL.Open(); command.ExecuteNonQuery(); } catch (Exception e) { ErrorLogging.logError(e); throw (e); } finally { connectionToSQL.Close(); connectionToSQL.Dispose(); } } } catch (Exception e) { ErrorLogging.logError(e); throw (e); } finally { //no connection to dispose, do nothing } }
public void UpdateShipment(IShipmentInfoDO shipment) { try { //create connection using (SqlConnection connectionToSQL = new SqlConnection(connectionString)) //create a command using (SqlCommand command = new SqlCommand("UPDATE_SHIPMENT", connectionToSQL)) { try { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 35; command.Parameters.AddWithValue("@ShipmentID", shipment.ShipmentID); command.Parameters.AddWithValue("@LocationID", shipment.LocationID); command.Parameters.AddWithValue("@Product", shipment.Product); command.Parameters.AddWithValue("@ProducerID", shipment.ProducerID); command.Parameters.AddWithValue("@QuantityInBu", shipment.QuantityInBu); command.Parameters.AddWithValue("@PricePerBushel", shipment.PricePerBushel); connectionToSQL.Open(); command.ExecuteNonQuery(); } catch (Exception e) { //error wrote to Log Files in same folder as this project ErrorLogging.LogError(e); throw e; } finally { } } } catch (Exception e) { throw e; } finally { //good to go } }
public ActionResult UpdateShipment(long ShipmentID) { ShipmentVM updateVM = new ShipmentVM(); if (Session["UserName"] != null && (int)Session["UserLevel"] <= 2) { IShipmentInfoDO shipment = _ShipmentAccess.ViewShipmentByID(ShipmentID); updateVM.Shipment = ShipmentMap.MapDOtoPO(shipment); //call to data layer method to get list of producers for drop down updateVM.Shipment.LocationDDL = PopulateLocationsDDL(); updateVM.Shipment.ProducerDDL = PopulateProducersDDL(); } else { RedirectToAction("Login", "User"); } return(View(updateVM)); }