public async Task <UserOrderList> AddUserOrderList(UserOrderList userOrderList) { userOrderList.AddedDate = DateTime.Now; await _context.UserOrderLists.AddAsync(userOrderList); await _context.SaveChangesAsync(); return(userOrderList); }
/// <summary> /// Gets the user order list. /// </summary> /// <param name="userId">The user identifier.</param> /// <param name="hostingPath">The hosting path.</param> /// <returns></returns> public List <UserOrderList> GetUserOrderList(long userId, string hostingPath) { List <UserOrderList> UserOrderList = new List <UserOrderList>(); try { SqlParameter[] parameters = new SqlParameter[1]; parameters[0] = new SqlParameter("USERID", userId); DataSet ds = DBHelper.GetDataTable("USERORDERLIST", parameters, DBHelper.ParseString(settings.Value.AppDbContext)); if (ds != null && ds.Tables != null && ds.Tables.Count > 0) { DataTable Order = ds.Tables[0]; DataTable OrderProduct = ds.Tables[1]; DataTable Invoice = ds.Tables[2]; DataTable InvoiceProduct = ds.Tables[3]; DataTable SizeDetail = ds.Tables[4]; DataTable Size = ds.Tables[5]; DataTable Category = ds.Tables[6]; if (Order != null && Order.Rows.Count > 0) { for (int o = 0; o < Order.Rows.Count; o++) { UserOrderList orderModel = new UserOrderList(); orderModel.OrderDate = DBHelper.ParseString(Convert.ToDateTime(Order.Rows[o]["OrderDate"])).Split(' ')[0]; orderModel.OrderId = DBHelper.ParseString(Order.Rows[o]["OrderId"]); orderModel.PayableAmount = DBHelper.ParseString(Order.Rows[o]["PayableAmount"]); orderModel.PONumber = DBHelper.ParseString(Order.Rows[o]["PONumber"]); orderModel.SubtotalAmount = DBHelper.ParseString(Order.Rows[o]["SubtotalAmount"]); orderModel.UniqueOrderId = DBHelper.ParseString(Order.Rows[o]["UniqueOrderId"]); List <UserOrderProductList> orderProductLists = new List <UserOrderProductList>(); List <UserOrderInvoiceList> userOrderInvoiceLists = new List <UserOrderInvoiceList>(); if (OrderProduct != null && OrderProduct.Rows.Count > 0) { DataRow[] drProduct = OrderProduct.Select("OrderFK='" + DBHelper.ParseString(Order.Rows[o]["OrderId"]) + "'"); if (drProduct != null && drProduct.Length > 0) { foreach (DataRow item in drProduct) { #region Image string image = string.Empty; if (!string.IsNullOrWhiteSpace(DBHelper.ParseString(item["Image"]))) { image = hostingPath + Constants.ProductImagesPath.Replace(@"\", "/") + "/" + DBHelper.ParseString(item["Image"]); } else { image = hostingPath + Constants.NoImageAvaliablePath.Replace(@"\", "/"); } #endregion #region Category string category = string.Empty; DataRow[] drCategory = Category.Select("ProductFK='" + DBHelper.ParseString(item["ProductId"]) + "'"); if (drCategory != null && drCategory.Length > 0) { foreach (var cat in drCategory) { category += cat["CategoryType"] + ","; } category = category.TrimEnd(','); } #endregion #region SizeRatio string sizeId = string.Empty; string sizeRatio = string.Empty; DataRow[] drSizeDetail = SizeDetail.Select("ProductFK='" + DBHelper.ParseString(item["ProductId"]) + "'"); if (drSizeDetail != null && drSizeDetail.Length > 0) { sizeId = DBHelper.ParseString(drSizeDetail[0]["SizeFK"]); DataRow[] drSize = Size.Select("SizeFK='" + sizeId + "'"); if (drSize != null && drSize.Length > 0) { foreach (var size in drSize) { sizeRatio += DBHelper.ParseString(size["Name"]) + "/"; } sizeRatio = sizeRatio.TrimEnd('/'); sizeRatio += " - "; foreach (var size in drSizeDetail) { sizeRatio += DBHelper.ParseString(size["Name"]) + "/"; } sizeRatio = sizeRatio.TrimEnd('/'); } } #endregion orderProductLists.Add(new UserOrderProductList { Price = DBHelper.ParseString(item["Price"]), ProductId = DBHelper.ParseString(item["ProductId"]), Quantity = DBHelper.ParseString(item["Quantity"]), ProductName = DBHelper.ParseString(item["Name"]), Subtotal = DBHelper.ParseString(item["SubtotalAmount"]), Image = image, Color = DBHelper.ParseString(item["ColorName"]), Category = category, SizeRatio = sizeRatio, ProductColorId = DBHelper.ParseString(item["ProductColorFK"]), }); } } orderModel.ProductList = orderProductLists; orderModel.TotalItems = DBHelper.ParseString(drProduct.Length); } if (Invoice != null && Invoice.Rows.Count > 0) { DataRow[] drInvoice = Invoice.Select("OrderFK='" + DBHelper.ParseString(Order.Rows[o]["OrderId"]) + "'"); if (drInvoice != null && drInvoice.Length > 0) { for (int i = 0; i < drInvoice.Length; i++) { UserOrderInvoiceList invoiceModel = new UserOrderInvoiceList(); invoiceModel.InvoiceDate = DBHelper.ParseString(Convert.ToDateTime(drInvoice[i]["InvoiceDate"])).Split(' ')[0]; invoiceModel.OrderId = DBHelper.ParseString(drInvoice[i]["OrderFK"]); invoiceModel.OrderInvoiceId = DBHelper.ParseString(drInvoice[i]["OrderInvoiceId"]); invoiceModel.PayableAmount = DBHelper.ParseString(drInvoice[i]["PayableAmount"]); invoiceModel.ShippingCharges = DBHelper.ParseString(drInvoice[i]["ShippingCharges"]); invoiceModel.Status = DBHelper.ParseString(drInvoice[i]["OrderStatus"]); invoiceModel.SubtotalAmount = DBHelper.ParseString(drInvoice[i]["SubtotalAmount"]); invoiceModel.TotalGSTAmount = DBHelper.ParseString(drInvoice[i]["TotalGSTAmount"]); invoiceModel.TrackingNumber = DBHelper.ParseString(drInvoice[i]["TrackingNumber"]); invoiceModel.UniqueOrderInvoiceId = DBHelper.ParseString(drInvoice[i]["UniqueInvoiceId"]); List <UserOrderProductList> orderInvoiceProductLists = new List <UserOrderProductList>(); DataRow[] drInvoiceProduct = InvoiceProduct.Select("OrderInvoiceFK='" + DBHelper.ParseString(drInvoice[i]["OrderInvoiceId"]) + "'"); if (drInvoiceProduct != null && drInvoiceProduct.Length > 0) { foreach (DataRow item in drInvoiceProduct) { #region Image string image = string.Empty; if (!string.IsNullOrWhiteSpace(DBHelper.ParseString(item["Image"]))) { image = hostingPath + Constants.ProductImagesPath.Replace(@"\", "/") + "/" + DBHelper.ParseString(item["Image"]); } else { image = hostingPath + Constants.NoImageAvaliablePath.Replace(@"\", "/"); } #endregion #region Category string category = string.Empty; DataRow[] drCategory = Category.Select("ProductFK='" + DBHelper.ParseString(item["ProductId"]) + "'"); if (drCategory != null && drCategory.Length > 0) { foreach (var cat in drCategory) { category += cat["CategoryType"] + ","; } category = category.TrimEnd(','); } #endregion #region SizeRatio string sizeId = string.Empty; string sizeRatio = string.Empty; DataRow[] drSizeDetail = SizeDetail.Select("ProductFK='" + DBHelper.ParseString(item["ProductId"]) + "'"); if (drSizeDetail != null && drSizeDetail.Length > 0) { sizeId = DBHelper.ParseString(drSizeDetail[0]["SizeFK"]); DataRow[] drSize = Size.Select("SizeFK='" + sizeId + "'"); if (drSize != null && drSize.Length > 0) { foreach (var size in drSize) { sizeRatio += DBHelper.ParseString(size["Name"]) + "/"; } sizeRatio = sizeRatio.TrimEnd('/'); sizeRatio += " - "; foreach (var size in drSizeDetail) { sizeRatio += DBHelper.ParseString(size["Name"]) + "/"; } sizeRatio = sizeRatio.TrimEnd('/'); } } #endregion orderInvoiceProductLists.Add(new UserOrderProductList { Price = DBHelper.ParseString(item["Price"]), ProductId = DBHelper.ParseString(item["ProductId"]), Quantity = DBHelper.ParseString(item["Quantity"]), ProductName = DBHelper.ParseString(item["Name"]), Subtotal = DBHelper.ParseString(item["SubtotalAmount"]), Image = image, Color = DBHelper.ParseString(item["ColorName"]), Category = category, SizeRatio = sizeRatio, ProductColorId = DBHelper.ParseString(item["ProductColorFK"]), }); } } invoiceModel.ProductLists = orderInvoiceProductLists; invoiceModel.TotalItems = DBHelper.ParseString(drInvoiceProduct.Length); userOrderInvoiceLists.Add(invoiceModel); } } orderModel.InvoiceList = userOrderInvoiceLists; } UserOrderList.Add(orderModel); } return(UserOrderList); } } } catch (Exception ex) { LogHelper.ExceptionLog(ex.Message + " ::::: " + ex.StackTrace); throw ex; } return(UserOrderList); }