public ActionResult UpdateSailboat(Int64 BoatID) { BoatDO item = _boatDataAccess.ViewBoatByID(BoatID); BoatPO boatToUpdate = BoatMap1.BoatDOtoBoatPO(item); return(View(boatToUpdate)); }
public ActionResult UpdateSailboat(BoatPO form) { ActionResult oresponse = null; try { if (ModelState.IsValid) { BoatDO dataObject = BoatMap1.BoatPOtoDO(form); _boatDataAccess.UpdateSailboats(dataObject); oresponse = RedirectToAction("ViewSailboats", "Boat"); } else { oresponse = View(form); } } catch (Exception ex) { logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace); } finally { } return(oresponse); }
//Home Page public ActionResult Index() { ActionResult oResponse = null; //Give the list to the view to display try { List <InvoiceDO> allInvoices = _invoiceDataAccess.ViewInvoices(); List <InvoiceBO> mappedInvoices = new List <InvoiceBO>(); foreach (InvoiceDO dataObject in allInvoices) { mappedInvoices.Add(HighestProfitMap.InvoiceDOtoInvoiceBO(dataObject)); } List <KeyValuePair <BoatPO, int> > topDisplay = new List <KeyValuePair <BoatPO, int> >(); List <KeyValuePair <Int64, int> > topBoats = InvoiceBLO.TopBoatsByInvoiceCount(mappedInvoices); foreach (KeyValuePair <Int64, int> record in topBoats) { BoatDO dataObject = _boatDataAccess.ViewBoatByID(record.Key); BoatPO boat = BoatMap1.BoatDOtoBoatPO(dataObject); topDisplay.Add(new KeyValuePair <BoatPO, int>(boat, record.Value)); } oResponse = View(topDisplay); } catch (Exception ex) { logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace); } finally { } return(oResponse); }
public void UpdateSailboats(BoatDO boat) { SqlConnection connection = null; SqlCommand updateBoatRowCommand = null; try { connection = new SqlConnection(_ConnectionString); updateBoatRowCommand = new SqlCommand("UPDATE_SAILBOAT", connection); updateBoatRowCommand.CommandType = CommandType.StoredProcedure; connection.Open(); updateBoatRowCommand.Parameters.AddWithValue("@BoatID", boat.BoatID); updateBoatRowCommand.Parameters.AddWithValue("@YearofBoat", boat.YearofBoat); updateBoatRowCommand.Parameters.AddWithValue("@BoatType", boat.BoatType); updateBoatRowCommand.Parameters.AddWithValue("@Length", boat.Length); updateBoatRowCommand.Parameters.AddWithValue("@Model", boat.Model); updateBoatRowCommand.Parameters.AddWithValue("@CostperDay", boat.CostperDay); updateBoatRowCommand.ExecuteNonQuery(); } catch (Exception ex) { logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace); throw ex; } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } }
public BoatDO ViewBoatByID(Int64 BoatID) { BoatDO boat = new BoatDO(); SqlConnection connection = null; SqlDataAdapter adapter = null; DataTable table = new DataTable(); SqlCommand command = null; try { connection = new SqlConnection(_ConnectionString); command = new SqlCommand("VIEW_BOAT_BY_ID", connection); command.CommandType = CommandType.StoredProcedure; connection.Open(); command.Parameters.AddWithValue("@BoatID", BoatID); adapter = new SqlDataAdapter(command); adapter.Fill(table); boat = BoatMap2.DataTableToList(table).FirstOrDefault(); } catch (Exception ex) { logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace); throw ex; } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } return(boat); }
public static BoatDO RowToItem(DataRow isource) { BoatDO to = new BoatDO(); to.BoatID = (Int64)isource["BoatID"]; if (isource["YearofBoat"] != DBNull.Value) { to.YearofBoat = (int)isource["YearofBoat"]; } if (isource["BoatType"] != DBNull.Value) { to.BoatType = isource["BoatType"].ToString(); } if (isource["Length"] != DBNull.Value) { to.Length = isource["Length"].ToString(); } if (isource["Model"] != DBNull.Value) { to.Model = isource["Model"].ToString(); } if (isource["CostperDay"] != DBNull.Value) { to.CostperDay = (Decimal)isource["CostperDay"]; } return(to); }
public static BoatDO BoatPOtoDO(BoatPO from) { BoatDO to = new BoatDO(); to.BoatID = from.BoatID; to.YearofBoat = from.YearofBoat; to.BoatType = from.BoatType; to.Length = from.Length; to.Model = from.Model; to.CostperDay = from.CostperDay; return(to); }
public ActionResult AddInvoice(InvoicePO form) { ActionResult oResponse = null; try { if (ModelState.IsValid) { //defines variables for boat .. and double days BoatDO boat = _boatDataAccess.ViewBoatByID(form.BoatID); double days = form.DateReturned.Subtract(form.DateChartered).TotalDays; //if greater than 0 if (days > 0) { //amount due = cost x days form.AmountDue = boat.CostperDay * (decimal)days; form.CostperDay = boat.CostperDay; InvoiceDO dataObject = InvoiceMap1.InvoicePOtoDO(form); _invoiceDataAccess.AddInvoice(dataObject); oResponse = RedirectToAction("ViewInvoice", "Invoice"); } else { TempData["ErrorMsg"] = "Date Returned can not be less than Date Chartered."; //TODO: fill select items oResponse = View(form); } } else { oResponse = View(form); } } catch (Exception ex) { logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace); } finally { } return(oResponse); }