public Boolean Update(CustomerOrderProduct customerOrderProduct) { using (SqlConnection con = new SqlConnection(_connectionString)) { con.Open(); SqlCommand cmd = new SqlCommand("usp_ECom_CustomerOrderProduct_Update", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("Id", customerOrderProduct.Id); cmd.Parameters.AddWithValue("CustomerOrderId", customerOrderProduct.CustomerOrderId); cmd.Parameters.AddWithValue("ProductId", customerOrderProduct.ProductId); cmd.Parameters.AddWithValue("Quantity", customerOrderProduct.Quantity); cmd.Parameters.AddWithValue("UnitPrice", customerOrderProduct.UnitOfMeasure); cmd.Parameters.AddWithValue("Tax", customerOrderProduct.Tax); cmd.Parameters.AddWithValue("UnitOfMeasure", customerOrderProduct.UnitOfMeasure); cmd.Parameters.AddWithValue("LastModifiedDate", customerOrderProduct.LastModifiedDate); cmd.Parameters.AddWithValue("LastModifiedBy", customerOrderProduct.LastModifiedBy); //Add more parameters from SP Int32 id = cmd.ExecuteNonQuery(); if (id > 0) { customerOrderProduct.Id = id; return(true); } } return(false); }
public CustomerOrderProduct Get(Int32 id) { using (SqlConnection con = new SqlConnection(_connectionString)) { con.Open(); SqlCommand cmd = new SqlCommand("usp_ECom_GetCustomerOrderProduct", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("Id", id); SqlDataReader reader = cmd.ExecuteReader(); CustomerOrderProduct customerOrderProduct = new CustomerOrderProduct(); while (reader.Read()) { customerOrderProduct.Id = id; customerOrderProduct.CustomerOrderId = Convert.ToInt32(reader["CustomerOrderId"]); customerOrderProduct.ProductId = Convert.ToInt32(reader["ProductId"]); customerOrderProduct.Quantity = Convert.ToDecimal(reader["Quantity"]); customerOrderProduct.UnitPrice = Convert.ToDecimal(reader["UnitPrice"]); customerOrderProduct.Tax = Convert.ToDecimal(reader["Tax"]); customerOrderProduct.UnitOfMeasure = Convert.ToString(reader["UnitOfMeasure"]); customerOrderProduct.LastModifiedDate = Convert.ToDateTime(reader["LastModifiedDate"]); customerOrderProduct.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]); customerOrderProduct.CreatedBy = Convert.ToString(reader["CreatedBy"]); customerOrderProduct.LastModifiedBy = Convert.ToString(reader["LastModifiedBy"]); //TO BE DONE, ORM process, map table data to class object } return(customerOrderProduct); } }
public List <CustomerOrderProduct> GetAll() { using (SqlConnection con = new SqlConnection(_connectionString)) { con.Open(); SqlCommand cmd = new SqlCommand("Select * from CustomerOrderProduct", con); SqlDataReader reader = cmd.ExecuteReader(); List <CustomerOrderProduct> customerOrderProducts = new List <CustomerOrderProduct>(); while (reader.Read()) { CustomerOrderProduct customerOrderProduct = new CustomerOrderProduct(); customerOrderProduct.CustomerOrderId = Convert.ToInt32(reader["CustomerOrderId"]); customerOrderProduct.ProductId = Convert.ToInt32(reader["ProductId"]); customerOrderProduct.Quantity = Convert.ToDecimal(reader["Quantity"]); customerOrderProduct.UnitPrice = Convert.ToDecimal(reader["UnitPrice"]); customerOrderProduct.Tax = Convert.ToDecimal(reader["Tax"]); customerOrderProduct.UnitOfMeasure = Convert.ToString(reader["UnitOfMeasure"]); customerOrderProduct.LastModifiedDate = Convert.ToDateTime(reader["LastModifiedDate"]); customerOrderProduct.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]); customerOrderProduct.CreatedBy = Convert.ToString(reader["CreatedBy"]); customerOrderProduct.LastModifiedBy = Convert.ToString(reader["LastModifiedBy"]); customerOrderProducts.Add(customerOrderProduct); //TO BE DONE, ORM process, map table data to class object } return(customerOrderProducts); } }
//public String CheckOut(IEnumerable<ShoppingCartProduct> Model) //{ // CustomerRepository customerRepo = new CustomerRepository(ConstantUtil.MyConnectionString); // Customer customer = customerRepo.GetById(1); // CustomerOrder co = new CustomerOrder(1, 25); // CustomerOrderRepository cor = new CustomerOrderRepository(ConstantUtil.MyConnectionString); // int orderId = cor.Insert(co); // List<CustomerOrderProduct> cops = new List<CustomerOrderProduct>(); // foreach (int scp in myModel.products) // { // CustomerOrderProduct temp = new CustomerOrderProduct(orderId, scp); // ProductRepository pr = new ProductRepository(ConstantUtil.MyConnectionString); // Product prod = pr.GetById(scp); // temp.Quantity = 100; // temp.UnitOfMeasure = prod.UnitOfMeasure; // temp.UnitPrice = prod.UnitPrice; // temp.CreatedBy = prod.CreatedBy; // temp.CreatedDate = prod.CreatedDate; // temp.LastModifiedBy = prod.LastModifiedBy; // temp.LastModifiedDate = prod.LastModifiedDate; // temp.Subtotal = 0; // cops.Add(temp); // } // return "Successfully"; //} public String CheckOut() { CustomerRepository customerRepo = new CustomerRepository(ConstantUtil.MyConnectionString); Customer customer = customerRepo.GetById(1); CustomerOrder co = new CustomerOrder(1, 25); CustomerOrderRepository cor = new CustomerOrderRepository(ConstantUtil.MyConnectionString); int orderId = cor.Insert(co); List <CustomerOrderProduct> cops = new List <CustomerOrderProduct>(); ShoppingCartProductRepository scpr = new ShoppingCartProductRepository(ConstantUtil.MyConnectionString); IEnumerable <ShoppingCartProduct> myModel = scpr.GetAll(); foreach (ShoppingCartProduct scp in myModel) { CustomerOrderProduct temp = new CustomerOrderProduct(orderId, scp.ProductId); //ProductRepository pr = new ProductRepository(ConstantUtil.MyConnectionString); //Product prod = pr.GetById(scp); temp.Quantity = scp.Quantity; temp.UnitOfMeasure = scp.UnitOfMeasure; temp.UnitPrice = scp.UnitPrice; temp.CreatedBy = scp.CreatedBy; temp.CreatedDate = scp.CreatedDate; temp.LastModifiedBy = scp.LastModifiedBy; temp.LastModifiedDate = scp.LastModifiedDate; temp.Subtotal = scp.SubTotal; //cops.Add(temp); CustomerOrderProductRepository copr = new CustomerOrderProductRepository(ConstantUtil.MyConnectionString); copr.Insert(temp); } return("Successfully"); }
public ActionResult CreateInvoice(int id) { var allConfirmedOrders = db.Database.SqlQuery <CustomerOrderProduct> ("SELECT Orders.OrderID, Customers.CustomerID, Customers.CustomerName, Products.ProductID, Products.ProductName, Products.UnitPrice, Orders.TotalPrice, Orders.OrderStatus FROM(((Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID) INNER JOIN OrderItems ON Orders.OrderID = OrderItems.OrderID) INNER JOIN Products ON Products.ProductID = OrderItems.ProductID) Where Customers.CustomerID = " + id + "").ToList(); List <CustomerOrderProduct> allRecords = new List <CustomerOrderProduct>(); foreach (var item in allConfirmedOrders) { CustomerOrderProduct obj2 = new CustomerOrderProduct() { CustomerID = item.CustomerID, OrderID = item.OrderID, CustomerName = item.CustomerName, ProductID = item.ProductID, ProductName = item.ProductName, UnitPrice = item.UnitPrice, TotalPrice = item.TotalPrice, OrderStatus = item.OrderStatus, OrderList = allConfirmedOrders.ToList() }; if (obj2.OrderStatus == "Ordered") { allRecords.Add(obj2); } } ViewBag.invoiceNumber = DateTime.Now.ToString("yyyyMMddHHmmss"); return(View(allRecords)); }
// GET: Orders/Edit/5 public ActionResult Edit(int id) { //Get data from database int CustomerID = (int)Session["CustomerID"]; int OrderID = id; Session["OrderID"] = id; Session["CustomerID"] = CustomerID; var toCancelOrder = db.Database.SqlQuery <CustomerOrderProduct> ("SELECT Orders.OrderID, Customers.CustomerID, Customers.CustomerName, Products.ProductID, Products.ProductName, Products.UnitPrice, Orders.TotalPrice, Orders.OrderStatus FROM(((Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID) INNER JOIN OrderItems ON Orders.OrderID = OrderItems.OrderID) INNER JOIN Products ON Products.ProductID = OrderItems.ProductID) Where Customers.CustomerID = " + CustomerID + "").ToList(); CustomerOrderProduct obj = new CustomerOrderProduct() { OrderList = toCancelOrder.Where(a => a.OrderStatus == "Ordered" && a.OrderID == OrderID).ToList() }; //static productlist List <Product> pr = new List <Product> { new Product() { ProductID = 1, ProductName = "Coffee", IsCheck = false, UnitPrice = 3.5 }, new Product() { ProductID = 2, ProductName = "Pizza", IsCheck = false, UnitPrice = 20 }, new Product() { ProductID = 3, ProductName = "Salad", IsCheck = false, UnitPrice = 9.75 }, new Product() { ProductID = 4, ProductName = "Dumpling", IsCheck = false, UnitPrice = 13 }, new Product() { ProductID = 5, ProductName = "Donut", IsCheck = false, UnitPrice = 2.75 } }; var previousSelectedProducts = obj.OrderList.Select(a => a.ProductName).ToArray(); //check item selected previously foreach (var item in pr) { if (previousSelectedProducts.Contains(item.ProductName)) { item.IsCheck = true; } } ProductList prList = new ProductList { Products = pr }; prList.Customer = db.Customers.Find(CustomerID); return(View(prList)); }
public ActionResult DeleteConfirmed(int id) { CustomerOrderProduct customerOrderProduct = db.CustomerOrderProducts.Find(id); db.CustomerOrderProducts.Remove(customerOrderProduct); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "CustomerOrderProductID,CustomerOrderID,Name,Price,Status,ImagePath,Created,LatestModify,Comment,MerchantID")] CustomerOrderProduct customerOrderProduct) { if (ModelState.IsValid) { db.Entry(customerOrderProduct).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customerOrderProduct)); }
// GET: CustomerOrderProducts/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CustomerOrderProduct customerOrderProduct = db.CustomerOrderProducts.Find(id); if (customerOrderProduct == null) { return(HttpNotFound()); } return(View(customerOrderProduct)); }
public ActionResult CustomerCancelOrder(int id) { int CustomerID = (int)Session["CustomerID"]; int OrderID = id; Session["OrderID"] = id; var toCancelOrder = db.Database.SqlQuery <CustomerOrderProduct> ("SELECT Orders.OrderID, Customers.CustomerID, Customers.CustomerName, Products.ProductID, Products.ProductName, Products.UnitPrice, Orders.TotalPrice, Orders.OrderStatus FROM(((Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID) INNER JOIN OrderItems ON Orders.OrderID = OrderItems.OrderID) INNER JOIN Products ON Products.ProductID = OrderItems.ProductID) Where Customers.CustomerID = " + CustomerID + "").ToList(); CustomerOrderProduct obj = new CustomerOrderProduct() { OrderList = toCancelOrder.Where(a => a.OrderStatus == "Ordered" && a.OrderID == OrderID).ToList() }; return(View(obj.OrderList)); }
public ActionResult CancelledOrders(int id) { var allConfirmedOrders = db.Database.SqlQuery <CustomerOrderProduct> ("SELECT Orders.OrderID, Customers.CustomerID, Customers.CustomerName, Products.ProductID, Products.ProductName, Products.UnitPrice, Orders.TotalPrice, Orders.OrderStatus FROM(((Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID) INNER JOIN OrderItems ON Orders.OrderID = OrderItems.OrderID) INNER JOIN Products ON Products.ProductID = OrderItems.ProductID) Where Customers.CustomerID = " + id + "").ToList(); CustomerOrderProduct obj = new CustomerOrderProduct() { OrderList = allConfirmedOrders.Where(a => a.OrderStatus == "Cancelled").ToList() }; //Find all orders List <int> orderIDList = new List <int>(); foreach (var a in obj.OrderList) { if (!orderIDList.Contains(a.OrderID)) { orderIDList.Add(a.OrderID); } } ViewBag.orderIDList = orderIDList; //Find all product name and concatinate string productString = string.Empty; List <string> productNameList = new List <string>(); foreach (var item in orderIDList) { var stringsColl = (obj.OrderList.Where(a => a.OrderID == item).Select(a => a.ProductName)); foreach (var items in stringsColl) { productString = productString + ", " + items; } string commaRemoved = productString.Substring(1, productString.Length - 1); productNameList.Add(commaRemoved); commaRemoved = string.Empty; productString = string.Empty; } ViewBag.stringCollectionProductName = productNameList; Session["CustomerID"] = id; return(View(obj.OrderList)); }
public SingleResult <InsertOrderResultDto> GetProductByIdList_UI(OrderModel order) { try { var userId = ClaimPrincipalFactory.GetUserId(User); var cc = _repository.Customer.FindByCondition(c => c.UserId == userId).FirstOrDefault(); var customerId = cc.Id; var today = DateTime.Now.AddDays(-1).Ticks; var orerProductList = new List <CustomerOrderProduct>(); var orderNo = customerId.ToString() + DateTimeFunc.TimeTickToShamsi(DateTime.Now.Ticks).Replace("/", "") + (_repository.CustomerOrder.FindByCondition(c => c.CustomerId == customerId && today > c.Cdate) .Count() + 1).ToString().PadLeft(3, '0'); order.ProductList.ForEach(c => { var product = _repository.Product.FindByCondition(x => x.Id == c.ProductId).First(); var ofer = _repository.Offer.FindByCondition(x => x.Id == c.OfferId).FirstOrDefault(); var packingType = _repository.ProductPackingType.FindByCondition(x => x.Id == c.PackingTypeId) .FirstOrDefault(); var statusId = _repository.Status.GetSatusId("CustomerOrderProduct", 2); var orderproduct = new CustomerOrderProduct { OrderCount = c.Count, ProductId = c.ProductId, Cdate = DateTime.Now.Ticks, CuserId = userId, OrderType = 1, ProductCode = product.Coding, ProductIncreasePrice = null, ProductName = product.Name, ProductPrice = product.Price, ProductOfferId = c.OfferId, ProductOfferCode = ofer?.OfferCode, ProductOfferPrice = (long?)(ofer != null ? (ofer.Value / 100 * product.Price) : 0), ProductOfferValue = ofer?.Value, PackingTypeId = packingType?.PackinggTypeId, PackingWeight = packingType == null ? 0 : packingType.Weight, PackingPrice = packingType == null ? 0 : packingType.Price, SellerId = product.SellerId, Weight = c.Count * product.Weight, FinalWeight = (c.Count * product.Weight) + (c.Count * (packingType == null ? 0 : packingType.Weight)), FinalStatusId = statusId }; orerProductList.Add(orderproduct); }); var offer = _repository.Offer.FindByCondition(c => c.Id == order.OfferId).FirstOrDefault(); var paking = _repository.PackingType.FindByCondition(c => c.Id == order.PaymentTypeId).FirstOrDefault(); var customerOrder = new CustomerOrder { Cdate = DateTime.Now.Ticks, CuserId = userId, CustomerAddressId = order.CustomerAddressId, CustomerDescription = order.CustomerDescription, CustomerId = customerId, FinalStatusId = _repository.Status.GetSatusId("CustomerOrder", 1), OfferId = order.OfferId, OrderPrice = orerProductList.Sum(x => ((x.PackingPrice + x.ProductPrice - x.ProductOfferPrice) * x.OrderCount)) }; customerOrder.OrderPrice = orerProductList.Sum(c => (c.ProductPrice + c.PackingPrice - c.ProductOfferPrice) * c.OrderCount); customerOrder.OfferPrice = (long?)(customerOrder.OrderPrice * (offer == null ? 0 : offer.Value / 100)); customerOrder.OfferValue = (int?)offer?.Value; customerOrder.OrderDate = DateTime.Now.Ticks; customerOrder.FinalWeight = orerProductList.Sum(x => x.FinalWeight); customerOrder.OrderNo = Convert.ToInt64(orderNo); customerOrder.OrderProduceTime = 0; customerOrder.OrderType = 1; customerOrder.OrderWeight = customerOrder.FinalWeight; customerOrder.PackingPrice = 0; customerOrder.PackingWeight = 0; customerOrder.PaymentTypeId = order.PaymentTypeId; customerOrder.PostServicePrice = 0; customerOrder.PostTypeId = order.PostTypeId; //customerOrder.TaxPrice = (long?)((customerOrder.OrderPrice - customerOrder.OfferPrice) * 0.09); //customerOrder.TaxValue = 9; customerOrder.TaxPrice = 0; customerOrder.TaxValue = 9; customerOrder.CustomerOrderProduct = orerProductList; var toCityId = _repository.CustomerAddress.FindByCondition(c => c.Id == order.CustomerAddressId).Include(c => c.City).Select(c => c.City.PostCode).FirstOrDefault(); var postType = _repository.PostType.FindByCondition(c => c.Id == order.PostTypeId).FirstOrDefault(); var payType = _repository.PaymentType.FindByCondition(c => c.Id == order.PaymentTypeId) .FirstOrDefault(); if (postType.IsFree.Value) { customerOrder.PostServicePrice = 0; } else { var post = new PostServiceProvider(); var postpriceparam = new PostGetDeliveryPriceParam { Price = (int)customerOrder.OrderPrice.Value, Weight = (int)customerOrder.FinalWeight.Value, ServiceType = postType?.Rkey ?? 2,// (int)customerOrder.PostTypeId, ToCityId = (int)toCityId, PayType = (int)(payType?.Rkey ?? 88) }; var postresult = post.GetDeliveryPrice(postpriceparam).Result; if (postresult.ErrorCode != 0) { throw new BusinessException(XError.IncomingSerivceErrors.PostSeerivcError()); } customerOrder.PostServicePrice = (postresult.PostDeliveryPrice + postresult.VatTax) / 10; } customerOrder.FinalPrice = customerOrder.OrderPrice + customerOrder.TaxPrice + customerOrder.PostServicePrice; _repository.CustomerOrder.Create(customerOrder); var request = new ZarinPallRequest { // amount = (int)((customerOrder.FinalPrice.Value + customerOrder.PostServicePrice) * 10), amount = (int)((customerOrder.FinalPrice.Value) * 10), description = "order NO: " + customerOrder.OrderNo, metadata = new ZarinPalRequestMetaData { mobile = "0" + cc.Mobile.ToString(), email = cc.Email } }; var zarinPal = new ZarinPal(); var res = zarinPal.Request(request); var customerOrderPayment = new CustomerOrderPayment { OrderNo = customerOrder.OrderNo.ToString(), TraceNo = res.authority, TransactionPrice = customerOrder.FinalPrice, TransactionDate = DateTime.Now.Ticks, Cdate = DateTime.Now.Ticks, CuserId = userId, PaymentPrice = customerOrder.FinalPrice, FinalStatusId = 26 }; customerOrder.CustomerOrderPayment.Add(customerOrderPayment); _repository.Save(); var result = new InsertOrderResultDto { OrderNo = customerOrder.OrderNo, CustomerOrderId = customerOrder.Id, BankUrl = "https://www.zarinpal.com/pg/StartPay/" + res.authority, RedirectToBank = true, PostPrice = customerOrder.PostServicePrice }; var finalres = SingleResult <InsertOrderResultDto> .GetSuccessfulResult(result); _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, order); return(finalres); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), order); return(SingleResult <InsertOrderResultDto> .GetFailResult(e.Message)); } }
public SingleResult <OrderPreViewResultDto> CustomerOrderPreview_UI(OrderModel order) { try { var orerProductList = new List <CustomerOrderProduct>(); order.ProductList.ForEach(c => { var product = _repository.Product.FindByCondition(x => x.Id == c.ProductId).First(); var ofer = _repository.Offer.FindByCondition(x => x.Id == c.OfferId).FirstOrDefault(); var packingType = _repository.ProductPackingType.FindByCondition(x => x.Id == c.PackingTypeId) .FirstOrDefault(); var statusId = _repository.Status.GetSatusId("CustomerOrderProduct", 2); var orderproduct = new CustomerOrderProduct { OrderCount = c.Count, ProductId = c.ProductId, ProductCode = product.Coding, ProductName = product.Name, ProductPrice = product.Price, ProductOfferId = c.OfferId, ProductOfferCode = ofer?.OfferCode, ProductOfferPrice = (long?)(ofer != null ? (ofer.Value / 100 * product.Price) : 0), ProductOfferValue = ofer?.Value, PackingTypeId = c.PackingTypeId, PackingWeight = packingType == null ? 0 : packingType.Weight, PackingPrice = packingType == null ? 0 : packingType.Price, SellerId = product.SellerId, Weight = c.Count * product.Weight, FinalWeight = (c.Count * product.Weight) + (c.Count * (packingType == null ? 0 : packingType.Weight)), FinalStatusId = statusId }; orerProductList.Add(orderproduct); }); var offer = _repository.Offer.FindByCondition(c => c.Id == order.OfferId).FirstOrDefault(); var paking = _repository.PackingType.FindByCondition(c => c.Id == order.PaymentTypeId).FirstOrDefault(); var customerOrder = new OrderPreViewResultDto(); customerOrder.OrderPrice = orerProductList.Sum(c => (c.ProductPrice + c.PackingPrice - c.ProductOfferPrice) * c.OrderCount); customerOrder.OfferPrice = (long?)(customerOrder.OrderPrice * (offer == null ? 0 : offer.Value / 100)); customerOrder.OfferValue = (int?)offer?.Value; customerOrder.FinalWeight = orerProductList.Sum(x => x.FinalWeight); customerOrder.OrderWeight = customerOrder.FinalWeight; customerOrder.PaymentTypeId = order.PaymentTypeId; customerOrder.PostServicePrice = 0; customerOrder.ProductList = orerProductList; var toCityId = _repository.CustomerAddress.FindByCondition(c => c.Id == order.CustomerAddressId).Include(c => c.City).Select(c => c.City.PostCode).FirstOrDefault(); var postType = _repository.PostType.FindByCondition(c => c.Id == order.PostTypeId).FirstOrDefault(); var payType = _repository.PaymentType.FindByCondition(c => c.Id == order.PaymentTypeId) .FirstOrDefault(); if (postType.IsFree.Value) { customerOrder.PostServicePrice = 0; } else { var post = new PostServiceProvider(); var postpriceparam = new PostGetDeliveryPriceParam { Price = (int)customerOrder.OrderPrice.Value, Weight = (int)customerOrder.FinalWeight.Value, ServiceType = postType?.Rkey ?? 2,// (int)customerOrder.PostTypeId, ToCityId = (int)toCityId, PayType = (int)(payType?.Rkey ?? 88) }; var postresult = post.GetDeliveryPrice(postpriceparam).Result; if (postresult.ErrorCode != 0) { throw new BusinessException(XError.IncomingSerivceErrors.PostSeerivcError()); } customerOrder.PostServicePrice = (postresult.PostDeliveryPrice + postresult.VatTax) / 10; } customerOrder.FinalPrice = customerOrder.OrderPrice + customerOrder.PostServicePrice; var finalres = SingleResult <OrderPreViewResultDto> .GetSuccessfulResult(customerOrder); _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, order); return(finalres); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), order); return(SingleResult <OrderPreViewResultDto> .GetFailResult(e.Message)); } }
public List <CustomerOrderProduct> GetAll() { using (SqlConnection con = new SqlConnection(_connectionString)) { con.Open(); SqlCommand cmd = new SqlCommand("Select * from CustomerOrderProduct", con); SqlDataReader reader = cmd.ExecuteReader(); //CustomerOrderProduct customerOrderProducts; List <CustomerOrderProduct> customerOrderProducts = new List <CustomerOrderProduct>(); CustomerOrderProduct customerOrderProduct; while (reader.Read()) { //customerOrderProducts = new CustomerOrderProduct(reader.GetInt32(0), reader.GetInt32(1)); //customerOrderProduct.CustomerOrderId = reader.GetInt32(0); if (reader["CustomerOrderId"] != null && reader["ProductId"] != null) { if (!reader.IsDBNull(0) && !reader.IsDBNull(1)) { customerOrderProduct = new CustomerOrderProduct(reader.GetInt32(0), reader.GetInt32(1)); if (!reader.IsDBNull(2)) { customerOrderProduct.ProductId = reader.GetInt32(2); } if (reader["Id"] != null) { customerOrderProduct.Id = Convert.ToInt32(reader["Id"]); } if (reader["Quantity"] != null) { if (!reader.IsDBNull(3)) { customerOrderProduct.Quantity = reader.GetDecimal(3); } } if (reader["UnitPrice"] != null) { customerOrderProduct.UnitPrice = reader.GetDecimal(4); } if (reader["UnitOfMeasure"] != null) { if (!reader.IsDBNull(5)) { customerOrderProduct.Tax = reader.GetDecimal(5); } } if (reader["Tax"] != null) { customerOrderProduct.UnitOfMeasure = reader.GetString(6); } if (reader["Subtotal"] != null) { customerOrderProduct.Subtotal = reader.GetDecimal(7); } if (reader["CreatedDate"] != null) { customerOrderProduct.CreatedDate = reader.GetDateTime(8); } if (reader["CreatedBy"] != null) { customerOrderProduct.LastModifiedDate = reader.GetDateTime(9); } if (reader["LastModifiedBy"] != null) { if (!reader.IsDBNull(10)) { customerOrderProduct.CreatedBy = reader.GetString(10); } } if (reader["LastModifiedDate"] != null) { customerOrderProduct.LastModifiedBy = reader.GetString(11); } customerOrderProducts.Add(customerOrderProduct); //TO BE DONE, ORM process, map table data to class object } } } return(customerOrderProducts); } }
public CustomerOrderProduct Get(Int32 id) { using (SqlConnection con = new SqlConnection(_connectionString)) { con.Open(); SqlCommand cmd = new SqlCommand("usp_ECom_CustomerOrderProduct_Select", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("Id", id); SqlDataReader reader = cmd.ExecuteReader(); CustomerOrderProduct customerOrderProduct; while (reader.Read()) { if (reader["CustomerOrderId"] != null && reader["ProductId"] != null) { if (!reader.IsDBNull(0) && !reader.IsDBNull(1)) { customerOrderProduct = new CustomerOrderProduct(reader.GetInt32(0), reader.GetInt32(1)); if (reader["Id"] != null) { customerOrderProduct.Id = Convert.ToInt32(reader["Id"]); } if (!reader.IsDBNull(2)) { customerOrderProduct.Quantity = reader.GetDecimal(2); } if (!reader.IsDBNull(6)) { customerOrderProduct.Subtotal = reader.GetDecimal(6); } if (reader["Quantity"] != null) { customerOrderProduct.UnitPrice = reader.GetDecimal(3); } if (reader["UnitPrice"] != null) { customerOrderProduct.Tax = reader.GetDecimal(4); } if (reader["UnitOfMeasure"] != null) { if (!reader.IsDBNull(5)) { customerOrderProduct.UnitOfMeasure = reader.GetString(5); } } if (reader["Tax"] != null) { customerOrderProduct.Subtotal = reader.GetDecimal(6); } if (reader["Subtotal"] != null) { customerOrderProduct.CreatedDate = reader.GetDateTime(7); } if (reader["CreatedDate"] != null) { customerOrderProduct.LastModifiedDate = reader.GetDateTime(8); } if (reader["CreatedBy"] != null) { customerOrderProduct.CreatedBy = reader.GetString(9); } if (reader["LastModifiedBy"] != null) { customerOrderProduct.LastModifiedBy = Convert.ToString(reader["LastModifiedBy"]); } if (reader["LastModifiedDate"] != null) { customerOrderProduct.LastModifiedDate = Convert.ToDateTime(reader["LastModifiedDate"]); if (!reader.IsDBNull(10)) { customerOrderProduct.LastModifiedBy = reader.GetString(10); } return(customerOrderProduct); } //TO BE DONE, ORM process, map table data to class object } } } return(null); } }