public ActionResult UpdateItem(ItemsPO form) { ActionResult response; //checking modelstate if (ModelState.IsValid) { try { //storing data to database ItemsDO ItemDO = Mapper.ItemsPOtoItemsDO(form); _ItemsDAO.UpdateItemEntryInformation(ItemDO); //setting response page response = RedirectToAction("ViewOrderByID", "Orders", new { form.OrderID }); } //logging errors and redirecting catch (SqlException sqlEx) { Logger.SqlErrorLog(sqlEx); response = View("Error"); } catch (Exception ex) { Logger.ErrorLog(ex); response = View("Error"); } } else { //returning to form view if model state is invalid response = View(form); } //return view return(response); }
public ActionResult UpdateItem(int ItemID) { ActionResult response; try { //retrieving data and displaying to user ItemsDO ItemDO = _ItemsDAO.ViewItemByID(ItemID); ItemsPO ItemPO = Mapper.ItemsDOtoItemsPO(ItemDO); //setting response view response = View(ItemPO); } //logging errors and redirecting catch (SqlException sqlEx) { Logger.SqlErrorLog(sqlEx); response = View("Error"); } catch (Exception ex) { Logger.ErrorLog(ex); response = View("Error"); } //return view return(response); }
//mapping back to Data Access layer public static ItemsDO ItemsPOtoItemsDO(ItemsPO from) { //mapping each individual attribute ItemsDO to = new ItemsDO(); to.ItemID = from.ItemID; to.Type = from.Type; to.SubType = from.SubType; to.Trait = from.Trait; to.Style = from.Style; to.Set = from.Set; to.Level = from.Level; to.Quality = from.Quality; to.OrderID = from.OrderID; to.Price = from.Price; //making it usable in future return(to); }
//Getting Item Data from the Database public static ItemsDO ReaderToItem(SqlDataReader from) { ItemsDO to = new ItemsDO(); //mapping data to.ItemID = (int)from["ItemID"]; to.Type = from["Type"] as string; to.SubType = from["SubType"] as string; to.Trait = from["Trait"] as string; to.Style = from["Style"] as string; to.Set = from["Set"] as string; to.Level = from["Level"] as string; to.Quality = from["Quality"] as string; to.OrderID = (int)from["OrderID"]; to.Price = (int)from["Price"]; //Returning Item Data return(to); }