// GET: api/GetOrderLines/5 public List <OrderLinesModel> Get(int id) { OrderLinesModel obj = new OrderLinesModel(); FetchOrderLines object1 = new FetchOrderLines(); return(object1.FetchOrderLinesLogic(id)); }
public ActionResult AddOrderLines(OrderLinesModel model) { ViewBag.Products = LoadProductModels(); if (ModelState.IsValid) { try { var productRemaining = CheckInventory(model.ProductID); if (productRemaining < model.QTY) { ViewBag.ErrorMessage = "Not enough inventory, only " + productRemaining + " remaining"; return(View(model)); } CreateOrderLine(model.OrderID, model.ProductID, model.QTY); return(RedirectToAction("Index/" + model.OrderID)); } catch (Exception e) { ViewBag.ErrorMessage = "That operation could not be completed. Please update the information and try again, or contact your system administrator."; return(View(model)); } } return(View(model)); }
public ActionResult EditOrderLines(OrderLinesModel model) { if (ModelState.IsValid) { try { var previousState = LoadOrderLine(model.OrderLineID); int changeInQuantity = model.QTY - previousState.QTY; var productRemaining = CheckInventory(model.ProductID); if (productRemaining < changeInQuantity) { ViewBag.ErrorMessage = "Not enough inventory, only " + productRemaining + " remaining"; return(View(model)); } AdjustInventory(model.ProductID, changeInQuantity); UpdateOrderLines(model.OrderLineID, model.OrderID, model.ProductID, model.QTY); return(RedirectToAction("Index/" + model.OrderID)); } catch (Exception e) { ViewBag.ErrorMessage = "That operation could not be completed. Please update the information and try again, or contact your system administrator."; return(View(model)); } } return(View(model)); }
public ActionResult DeleteOrderLines(OrderLinesModel model) { var previousState = LoadOrderLine(model.OrderLineID); try { RemoveOrderLine(model.OrderLineID); } catch (Exception e) { ViewBag.ErrorMessage = "That operation could not be completed. Please update the information and try again, or contact your system administrator."; return(View(model)); } return(RedirectToAction("Index/" + model.OrderID)); }
public static int RemoveOrderLine(int orderLineID) { var previousState = LoadOrderLine(orderLineID); AdjustInventory(previousState.ProductID, previousState.QTY * -1); OrderLinesModel data = new OrderLinesModel { OrderLineID = orderLineID }; string sql = @"delete from dbo.orderlines WHERE OrderLineID = @OrderLineID;"; return(SqlDataAccess.Execute(sql, data)); }
public static int UpdateOrderLines(int orderLineID, int orderID, int productID, int qty) { OrderLinesModel data = new OrderLinesModel { OrderLineID = orderLineID, OrderID = orderID, ProductID = productID, QTY = qty }; string sql = @"update dbo.orderlines set ProductID = @ProductID, QTY = @QTY WHERE OrderLineID = @OrderLineID;"; return(SqlDataAccess.Execute(sql, data)); }
// Fetches orderlines based on userID public List <OrderLinesModel> FetchOrderLinesLogic(int id) { List <OrderLinesModel> l1 = new List <OrderLinesModel>(); OrderLinesModel temp = new OrderLinesModel(); var con = @"Data Source=IL013449;Initial Catalog=Test;User ID=sa;Password=~$ystem32"; //Connection String SqlConnection myConnection = new SqlConnection(con); SqlCommand command = new SqlCommand("select * from OrderLines where USERID = " + id + "", myConnection); SqlDataReader myreader; myConnection.Open(); myreader = command.ExecuteReader(); if (myreader.HasRows) { while (myreader.Read()) { l1.Add(new OrderLinesModel() { ID = myreader[0].ToString(), OrderID = myreader[1].ToString(), UserID = myreader[2].ToString(), ProductID = myreader[3].ToString(), Quantity = myreader[4].ToString() }); // ID = Convert.ToInt32(myreader[0]), Name = myreader[1].ToString(), Author = myreader[2].ToString(), Description = myreader[3].ToString(), Price = Convert.ToSingle(myreader[4]), Quantity = Convert.ToInt32(myreader[5]), CategoryID = Convert.ToInt32(myreader[6]), IconURL = myreader[7].ToString() }); } } return(l1); }
public static void CreateOrderLine(int orderID, int productID, int totalQuantity) { AdjustInventory(productID, totalQuantity); OrderLinesModel data = new OrderLinesModel { OrderID = orderID, ProductID = productID, QTY = totalQuantity }; string sql = @"insert into dbo.orderlines (OrderID, ProductID, QTY) values (@OrderID, @ProductID, @QTY);"; try { SqlDataAccess.Execute(sql, data); } catch (System.Exception) { AdjustInventory(productID, totalQuantity * -1); throw; } }