public PcDO pcDOtoBLL(BLL_Model form) { PcDO to = new PcDO(); to.Price = form.price; return(to); }
public BLL_Model MapperBLLtoPCDO(PcDO from) { BLL_Model to = new BLL_Model(); to.price = from.Price; return(to); }
public ActionResult Delete(long pcID) { ActionResult response; if ((string)Session["RoleName"] == "Admin") { if ((int)Session["PcID"] > 0) { PcDO pc = pcDAO.ViewDetails((int)Session["PcID"]); PC deletedPC = _mapper.MapDoToPO(pc); pcDAO.DeletePC(deletedPC.PcID); response = RedirectToAction("Store", "PC"); } else { response = RedirectToAction("Store", "Store"); } Session.Remove("PcID"); return(response); } else { response = RedirectToAction("Store", "PC"); } return(response); }
public ActionResult Update() { ActionResult response; if ((string)Session["RoleName"] == "Admin") { //check id CANT be default or less than 0 if ((int)Session["PcID"] > 0) { PcDO pcDo = pcDAO.ViewDetails((int)Session["PcID"]); PC pcPO = _mapper.MapDoToPO(pcDo); response = View(pcPO); } else { response = RedirectToAction("Index", "Home"); } } else { response = RedirectToAction("Store", "PC"); } return(response); //Request.UrlReferrer }
/// <summary> /// We Create a new pc using the values mapped to the pcDO /// </summary> /// <param name="newPC"></param> public void CreatePC(PcDO newPC) { try { // We create our connecton and command and we set our commmand limits. //We then add the pcDO values mapped to the sql parameter using (SqlConnection pcShopperConnection = new SqlConnection(_ConnectionString)) using (SqlCommand createPC = new SqlCommand("ADD_PC", pcShopperConnection)) { createPC.CommandType = CommandType.StoredProcedure; createPC.CommandTimeout = 60; createPC.Parameters.AddWithValue("@PcName", newPC.PcName); createPC.Parameters.AddWithValue("@Cpu", newPC.Cpu); createPC.Parameters.AddWithValue("@Motherboard", newPC.MotherBoard); createPC.Parameters.AddWithValue("@Gpu", newPC.Gpu); createPC.Parameters.AddWithValue("@Ram", newPC.Ram); createPC.Parameters.AddWithValue("@PowerSupply", newPC.PowerSupply); createPC.Parameters.AddWithValue("@UserID", newPC.UserID); createPC.Parameters.AddWithValue("@Price", newPC.Price); //We then open the connection and execute the query pcShopperConnection.Open(); createPC.ExecuteNonQuery(); } } catch (SqlException ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } }
/// <summary> /// We go and update the pc based on the information we were given inside the view when we mapped to a Data layer. /// </summary> /// <param name="pc"></param> public void UpdatePc(PcDO pc) { try { using (SqlConnection pcConnection = new SqlConnection(_ConnectionString)) using (SqlCommand updatePC = new SqlCommand("UPDATE_PC", pcConnection)) { updatePC.CommandType = CommandType.StoredProcedure; updatePC.CommandTimeout = 60; updatePC.Parameters.AddWithValue("@PCID", pc.PcId); updatePC.Parameters.AddWithValue("@PcName", pc.PcName); updatePC.Parameters.AddWithValue("@Price", pc.Price); updatePC.Parameters.AddWithValue("@CPU", pc.Cpu); updatePC.Parameters.AddWithValue("@MotherBoard", pc.Price); updatePC.Parameters.AddWithValue("@GPU", pc.Gpu); updatePC.Parameters.AddWithValue("@Ram", pc.Ram); updatePC.Parameters.AddWithValue("@PowerSupply", pc.PowerSupply); updatePC.Parameters.AddWithValue("@UserID", pc.UserID); pcConnection.Open(); updatePC.ExecuteNonQuery(); } } catch (SqlException ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } try { using (SqlConnection pcConnection = new SqlConnection(_ConnectionString)) using (SqlCommand updatePC = new SqlCommand("UPDATE_PC", pcConnection)) { updatePC.CommandType = CommandType.StoredProcedure; updatePC.CommandTimeout = 60; updatePC.Parameters.AddWithValue("@PCID", pc.PcId); updatePC.Parameters.AddWithValue("@PcName", pc.PcName); updatePC.Parameters.AddWithValue("@Price", pc.Price); pcConnection.Open(); updatePC.ExecuteNonQuery(); } } catch (SqlException ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } }
public ActionResult ConfirmOrder(Order form) { //Prepare the model to be viewed. //Do not call on the DAO ActionResult response; long PCID = (int)Session["PcID"]; try { long userId = (long)Session["UserId"]; string Username = (string)Session["Username"]; //Map User UserDO userDO = userDao.ViewUserByID(userId); User user = userMapper.MapDOtoPO(userDO); PcDO pc = pcDAO.ViewDetails(form.PcID); PC mappedPc = pcMapper.MapDoToPO(pc); if (ModelState.IsValid) { OrderDO OrderObject = new OrderDO() { pcID = mappedPc.PcID, pcName = mappedPc.PcName, Address = form.Address, Country = form.Country, price = mappedPc.Price, userID = pc.UserID, userName = pc.Username }; ordersDAO.CreateOrder(OrderObject); response = RedirectToAction("Store", "PC"); } else { response = RedirectToAction("Store", "Pc"); } } catch { response = View(form); } return(response); }
/// <summary> /// We go and grab the details of the pc based on the PC ID we were given. /// </summary> /// <param name="pcID"></param> /// <returns></returns> public PcDO ViewDetails(long pcID) { PcDO viewPcs = new PcDO(); try { //Getting Things ready to find our specific pc using (SqlConnection pcConnection = new SqlConnection(_ConnectionString)) using (SqlCommand details = new SqlCommand("VIEW_PC", pcConnection)) { details.CommandType = CommandType.StoredProcedure; details.CommandTimeout = 60; details.Parameters.AddWithValue("@PCID", pcID); pcConnection.Open(); using (SqlDataReader readDetails = details.ExecuteReader()) { if (readDetails.Read()) { //Run Sql reader to find info and make equal to pc property viewPcs.PcId = readDetails["PcID"] != DBNull.Value ? (long)readDetails["PcID"] : 0; viewPcs.UserID = readDetails["UserID"] != DBNull.Value ? (long)readDetails["UserID"] : 0; viewPcs.PcName = readDetails["PcName"] != DBNull.Value ? (string)readDetails["PcName"] : null; viewPcs.Cpu = readDetails["Cpu"] != DBNull.Value ? (string)readDetails["Cpu"] : null; viewPcs.MotherBoard = readDetails["Motherboard"] != DBNull.Value ? (string)readDetails["Motherboard"] : null; viewPcs.Gpu = readDetails["Gpu"] != DBNull.Value ? (string)readDetails["GPu"] : null; viewPcs.Ram = readDetails["Ram"] != DBNull.Value ? (string)readDetails["Ram"] : null; viewPcs.PowerSupply = readDetails["PowerSupply"] != DBNull.Value ? (string)readDetails["PowerSupply"] : null; viewPcs.Username = readDetails["Username"] != DBNull.Value ? (string)readDetails["Username"] : null; viewPcs.Price = readDetails["Price"] != DBNull.Value ? (int)readDetails["Price"] : 0; } } } } catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); } catch (Exception ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } return(viewPcs); }
public ActionResult Update(PC form) { ActionResult response; if (ModelState.IsValid) { PcDO pcDO = _mapper.MapPOToDo(form); pcDAO.UpdatePc(pcDO); response = RedirectToAction("Store", "PC"); } else { response = View(form); } Session.Remove("PcID"); return(response); }
public PcDO MapPOToDo(PC from) { PcDO to = new PcDO(); to.PcId = from.PcID; to.Cpu = from.Cpu; to.Gpu = from.Gpu; to.MotherBoard = from.Motherboard; to.PcName = from.PcName; to.PowerSupply = from.Powersupply; to.Price = from.Price; to.Ram = from.Ram; to.UserID = from.UserID; from.UserName = from.UserName; return(to); }
public PC MapDoToPO(PcDO from) { PC to = new PC(); to.PcID = from.PcId; to.Cpu = from.Cpu; to.Gpu = from.Gpu; to.Motherboard = from.MotherBoard; to.PcName = from.PcName; to.Powersupply = from.PowerSupply; to.Price = from.Price; to.Ram = from.Ram; to.UserName = from.Username; to.UserID = from.UserID; return(to); }
/// <summary> /// We view all the details of the pc by the pcID /// </summary> /// <param name="pcID"></param> /// <returns></returns> public ActionResult PCDetails(int pcID) { ActionResult response; //check id CANT be default or less than 0 if (pcID > 0) { Session["PcID"] = pcID; PcDO pcDO = pcDAO.ViewDetails((int)Session["PcID"]); PC pcPO = _mapper.MapDoToPO(pcDO); response = View(pcPO); } else { response = RedirectToAction("Store", "Store"); } return(response); }
public PcDO MapReaderToSingle(SqlDataReader reader) { PcDO result = new PcDO(); if (reader["PCID"] != DBNull.Value) { result.PcId = (long)reader["PCID"]; } if (reader["PcName"] != DBNull.Value) { result.PcName = (string)reader["PcName"]; } if (reader["Gpu"] != DBNull.Value) { result.Gpu = (string)reader["Gpu"]; } if (reader["Cpu"] != DBNull.Value) { result.Cpu = (string)reader["Cpu"]; } if (reader["Motherboard"] != DBNull.Value) { result.MotherBoard = (string)reader["Motherboard"]; } if (reader["Ram"] != DBNull.Value) { result.Ram = (string)reader["Ram"]; } if (reader["PowerSupply"] != DBNull.Value) { result.PowerSupply = (string)reader["PowerSupply"]; } if (reader["Price"] != DBNull.Value) { result.Price = (int)reader["Price"]; } return(result); }
public ActionResult CreatePC(PC form) { ActionResult response; try { //if all the information is here we can let them create their pc if (ModelState.IsValid) { PcDO SellerObject = new PcDO() { PcName = form.PcName, Cpu = form.Cpu, Gpu = form.Gpu, MotherBoard = form.Motherboard, Ram = form.Ram, PowerSupply = form.Powersupply, Price = form.Price, Username = Session["UserName"].ToString(), UserID = Convert.ToInt64(Session["UserID"]) }; //We create the pc here using the seller object we just made up above with all the information from the view pcDAO.CreatePC(SellerObject); response = RedirectToAction("Store", "Pc"); } //Return the form if the information wasnt provided else { response = View(form); } } //If the try fails then we return to the login page catch { response = RedirectToAction("Login", "Account"); } return(response); }
/// <summary> /// We view three items in the store to display before we give PC Details /// </summary> /// <returns></returns> public List <PcDO> ViewShop() { //We set a list to hold all the information in the database. List <PcDO> shopList = new List <PcDO>(); try { //We gather our connection and command string tied to the the sql procedure using (SqlConnection pcConnection = new SqlConnection(_ConnectionString)) using (SqlCommand viewShop = new SqlCommand("VIEW_Store", pcConnection)) { //We open our connection and set the command as a stored procedure viewShop.CommandType = CommandType.StoredProcedure; pcConnection.Open(); //While its reading we execute our reader and then map every thing in the those three columns to the list above using (SqlDataReader sqlReader = viewShop.ExecuteReader()) { while (sqlReader.Read()) { PcDO pc = mapper.Shop(sqlReader); shopList.Add(pc); } } } } //We catch any exceptions if there is any of them if not then we will return the list to the view. catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); } catch (Exception ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } return(shopList); }
public PcDO Shop(SqlDataReader reader) { PcDO pcDO = new PcDO(); if (reader["PcID"] != DBNull.Value) { pcDO.PcId = (long)reader["PcID"]; } if (reader["PcName"] != DBNull.Value) { pcDO.PcName = (string)reader["PcName"]; } if (reader["Price"] != DBNull.Value) { pcDO.Price = (int)reader["Price"]; } if (reader["UserName"] != DBNull.Value) { pcDO.Username = (string)reader["UserName"]; } return(pcDO); }
public ActionResult ConfirmOrder(long pcID) { ActionResult response; if (!((string)Session["RoleName"] == null)) { Order order = new Order(); order.PcID = pcID; if (pcID > 0) { long userId = (long)Session["UserId"]; string Username = (string)Session["Username"]; //Map User UserDO userDO = userDao.ViewUserByID(userId); User user = userMapper.MapDOtoPO(userDO); PcDO pc = pcDAO.ViewDetails(pcID); PC mappedPc = pcMapper.MapDoToPO(pc); try { if (ModelState.IsValid) { OrderDO OrderObject = new OrderDO() { pcID = mappedPc.PcID, pcName = mappedPc.PcName, Address = user.Address, Country = user.Country, OrderID = order.OrderID, price = mappedPc.Price, userID = user.UserID, userName = user.Username }; OrderDO orderDo = ordersDAO.ViewOrderByPCID(pcID); Order orderPo = orderMapper.MapDoToPO(orderDo); response = View(orderPo); } else { response = RedirectToAction("Store", "Pc"); } } catch { response = RedirectToAction("Login", "Account"); } return(response); } else { response = RedirectToAction("Store", "Store"); } return(View()); } else { response = RedirectToAction("Login", "Account"); } return(response); }