public async Task <ApiResponse> DeleteUser(int id) { try { var user = await _userRepository.Queryable.Where(u => u.Id == id).GetFirstOrDefaultAsync(); user.Status = Constrants.USER_STATUS_INACTIVE; _userRepository.Update(user); await _userRepository.SaveChangesAsync(); return(new ApiResponse() { Status = "success", Message = "Successfully delete user" }); } catch (Exception ex) { return(new ApiResponse() { Status = "fail", Message = ex.Message }); } }
public async Task <ApiResponse> UpdateShoppingCartPaymentMethod(int userId, string selectedPayment) { try { var shoppingCart = await GetCart(userId); if (!string.IsNullOrEmpty(selectedPayment)) { shoppingCart.PaymentMethod = selectedPayment; } _shoppingCartRepository.Update(shoppingCart); await _shoppingCartRepository.SaveChangesAsync(); return(new ApiResponse() { Status = "success", Message = "Successfully Update Shopping Cart Payment Method" }); } catch (Exception ex) { return(new ApiResponse() { Status = "fail", Message = ex.Message }); } }
public async Task <ApiResponse> UpdateShoppingCart(int userId, ShoppingItem shoppingItem) { try { var shoppingCart = await GetCart(userId); var user = await _userRepository.GetUserByAccount(userId); int shoppingItemExists = _shoppingItemRepository.Queryable.Where(si => si.ShoppingCartId == shoppingCart.Id && si.ProductId == shoppingItem.Product.Id && si.Status == "0").Count(); if (shoppingItemExists > 0) { var shoppingItemModel = await _shoppingItemRepository.Queryable.Where(si => si.ShoppingCartId == shoppingCart.Id && si.ProductId == shoppingItem.Product.Id && si.Status == "0").GetFirstOrDefaultAsync(); shoppingItemModel.Amount += shoppingItem.Amount; shoppingItemModel.Packaging = shoppingItem.Packaging; _shoppingItemRepository.Update(shoppingItemModel); await _shoppingItemRepository.SaveChangesAsync(); } else { ShoppingItem si = new ShoppingItem() { Amount = shoppingItem.Amount, ProductId = shoppingItem.Product.Id, ShoppingCartId = shoppingCart.Id, Status = "0", Packaging = shoppingItem.Packaging }; _shoppingItemRepository.Create(si); await _shoppingItemRepository.SaveChangesAsync(); } shoppingCart.TotalItems += shoppingItem.Amount; updateShoppingCartPrice(shoppingCart, user, shoppingItem); _shoppingCartRepository.Update(shoppingCart); await _shoppingCartRepository.SaveChangesAsync(); return(new ApiResponse() { Status = "success", Message = "Successfully add " + shoppingItem.Product.Name + " to shopping cart" }); } catch (Exception ex) { return(new ApiResponse() { Status = "fail", Message = ex.Message }); } }
public async Task <ApiResponse> UpdateOrder(Order order) { try { _orderDataRepository.Update(order); await _orderDataRepository.SaveChangesAsync(); return(new ApiResponse() { Status = "success", Message = "Successfully update order" }); } catch (Exception ex) { return(new ApiResponse() { Status = "fail", Message = ex.Message }); } }
public async Task <ApiResponse> UpdateProduct(Product product) { try { _productDataRepository.Update(product); await _productDataRepository.SaveChangesAsync(); return(new ApiResponse() { Status = "success", Message = "Successfully update product" }); } catch (Exception ex) { return(new ApiResponse() { Status = "fail", Message = ex.Message }); } }
public async Task <ApiResponse> UpdateHeadInfomation(HeadInformation headInformation) { try { _headInformationDataRepository.Update(headInformation); await _headInformationDataRepository.SaveChangesAsync(); return(new ApiResponse() { Status = "success", Message = "Successfully update Head Infomation" }); } catch (Exception ex) { return(new ApiResponse() { Status = "fail", Message = ex.Message }); } }
public async Task <ApiResponse> AddOrder(ShoppingCart cart, double gst, double priceExclGst, double discount) { try { Order order = new Order() { CreatedDate = DateTime.Now, TotalItems = cart.TotalItems, TotalPrice = cart.TotalPrice, OrderStatus = "Unprocessed", UserId = cart.UserId, ShoppingCartId = cart.Id, InvoiceNo = DateTime.Now.ToString("yyyyMMddHHmmss"), ClientMessage = cart.PaymentMethod == "onaccount" ? "ON ACCOUNT" : "PREPAYMENT", AdminMessage = "", Balance = 0 }; _orderDataRepository.Create(order); int orderId; if ((await _orderDataRepository.Queryable.GetListAsync()).Count < 1) { orderId = 1; } else { orderId = _orderDataRepository.Queryable.Last().Id + 1; } var currentUser = await userRepository.GetUserByAccount(cart.UserId); double priceIncGst = priceExclGst + gst; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<div style='padding: 0; margin: 0; width:100%; height: 100%; background:#fbfaf7;'>"); stringBuilder.Append("<table width='100%' height='100%' align='center' cellspacing='0' cellpadding='0' bgcolor='#fbfaf7'>"); stringBuilder.Append("<tbody>"); stringBuilder.Append("<tr><td style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545'> </td></tr>"); stringBuilder.Append("<tr>"); stringBuilder.Append("<td style='color:#343731;'><table width='600px' bgcolor='#ffffff' cellspacing='0' cellpadding='0' align='center' border='0' style='border:1px solid #232323;text-align:center'><tbody><tr><td style='padding:10px;color:#343731'>"); stringBuilder.Append("<h2 style='font-weight:400;text-transform:uppercase'>Trojan Trading Company PTY LTD</h2>"); stringBuilder.Append("</td></tr>"); stringBuilder.Append("<tr style='text-align:left'><td style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545'><table width='90%'><tbody>"); stringBuilder.Append("<tr><td valign='top' width='50%' style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545'><h3 style='margin:15px 20px 10px 20px;font-size:1.1em;color:#454545;text-align:left'>Shipping Address</h3>"); stringBuilder.Append("<p style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545;margin:12px 20px 10px 20px;margin-bottom:0'>" + currentUser.BussinessName + "<br>"); stringBuilder.Append(currentUser.ShippingStreetNumber + " " + currentUser.ShippingAddressLine + "<br> " + currentUser.ShippingSuburb + ", " + currentUser.ShippingState + ", " + currentUser.ShippingPostCode + "<br>"); stringBuilder.Append("<strong>Email:</strong><a href='" + currentUser.Email + "' target='_blank'>" + currentUser.Email + "</a><br><strong>Phone:</strong>" + currentUser.Phone + "</p></td>"); stringBuilder.Append("<td valign='top' width='50%' style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545'><h3 style='margin:15px 20px 10px 20px;font-size:1.1em;color:#454545;text-align:left'>Billing Address</h3>"); stringBuilder.Append("<p style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545;margin:12px 20px 10px 20px;margin-bottom:0'>" + currentUser.BussinessName + "<br>"); stringBuilder.Append(currentUser.BillingStreetNumber + " " + currentUser.BillingAddressLine + "<br> " + currentUser.BillingSuburb + ", " + currentUser.BillingState + ", " + currentUser.BillingPostCode + "<br>"); stringBuilder.Append("<strong>Email:</strong><a href='" + currentUser.Email + "' target='_blank'>" + currentUser.Email + "</a><br><strong>Phone:</strong>" + currentUser.Phone + "</p></td>"); stringBuilder.Append("</tr></tbody></table></td></tr>"); stringBuilder.Append("</tbody></table></td></tr>"); stringBuilder.Append("<tr><td width='600' style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545'>"); stringBuilder.Append("<table cellspacing='0' cellpadding='0' width='600' align='center' bgcolor='#ffffff' border='0' style='border-right:1px solid #d3d3d3;border-left:1px solid #d3d3d3'>"); stringBuilder.Append("<tbody><tr><td align='center' style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545'> </td></tr>"); stringBuilder.Append("<tr><td style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545'>"); stringBuilder.Append("<h3 style='margin:15px 20px 10px 20px;font-size:1.1em;color:#454545;text-align:center'>Order #" + share.RandomString(4, true) + share.RandomNumber(1000, 9999).ToString() + " for Customer " + currentUser.Account + "</h3>"); stringBuilder.Append("</td></tr>"); stringBuilder.Append("<tr><td style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545'><table width='90%' cellspacing='0' cellpadding='0' align='center' bgcolor='#ffffff' border='0'>"); stringBuilder.Append("<tbody><tr>"); stringBuilder.Append("<td style='padding:1em 0.25em;border-bottom:1px solid #c4c4c4'></td>"); stringBuilder.Append("<td style='padding:1em 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><strong style ='font-size:10px'>Packaging</strong></td>"); stringBuilder.Append("<td style='padding:1em 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><strong style ='font-size:10px'>Original Price</strong></td>"); stringBuilder.Append("<td style='padding:1em 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><strong style='font-size:10px'>Buy Price</strong></td>"); stringBuilder.Append("<td style='padding:1em 0.25em;border-bottom:1px solid #c4c4c4;text-align:center'><strong style ='font-size:10px'>Order Qty</strong></td>"); stringBuilder.Append("<td style='padding:1em 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><strong style='font-size:10px'>Line Amount</strong></td></tr>"); foreach (var item in cart.ShoppingItems) { stringBuilder.Append("<tr><td style='padding:0 0.25em;border-bottom:1px solid #c4c4c4'><h4 style='margin:0'>" + item.Product.Name + "</h4></td>"); stringBuilder.Append("<td style='padding:0 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><p style='font:12px/1.5 Arial,Helvetica,sans-serif;margin:0 0 0 0'>" + item.Packaging + "</p></td>"); stringBuilder.Append("<td style='padding:0 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><p style='font:12px/1.5 Arial,Helvetica,sans-serif;margin:0 0 0 0'>$" + item.Product.OriginalPrice + "</p></td>"); if (currentUser.Role.ToLower() == "agent") { stringBuilder.Append("<td style='padding:0 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><strong>$" + String.Format("{0:0.00}", item.Product.AgentPrice) + "</strong></td>"); } else if (currentUser.Role.ToLower() == "wholesaler") { stringBuilder.Append("<td style='padding:0 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><strong>$" + String.Format("{0:0.00}", item.Product.WholesalerPrice) + "</strong></td>"); } stringBuilder.Append("<td style='padding:0 0.25em;border-bottom:1px solid #c4c4c4;text-align:center'>" + item.Amount + "</td>"); if (currentUser.Role.ToLower() == "agent") { stringBuilder.Append("<td style='padding:0 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><span><strong>$" + String.Format("{0:0.00}", item.Product.AgentPrice * item.Amount) + "</strong></span></td></tr>"); } else if (currentUser.Role.ToLower() == "wholesaler") { stringBuilder.Append("<td style='padding:0 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><span><strong>$" + String.Format("{0:0.00}", item.Product.WholesalerPrice * item.Amount) + "</strong></span></td></tr>"); } } stringBuilder.Append("</tbody>"); stringBuilder.Append("<tfoot>"); stringBuilder.Append("<tr><td colspan='2'> </td><td colspan='3' width='100' style='padding:0.5em 0.25em;border-bottom:1px solid #c4c4c4'>Payment Method</td>"); stringBuilder.Append("<td width='100' style='padding:0.5em 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><strong><span>" + String.Format("{0}", cart.PaymentMethod == "onaccount" ? "On Account" : "Prepayment") + "</span></strong></td></tr>"); stringBuilder.Append("<tr><td colspan='2'> </td><td colspan='3' width='100' style='padding:0.5em 0.25em;border-bottom:1px solid #c4c4c4'>Total Price Excl.GST</td>"); stringBuilder.Append("<td width='100' style='padding:0.5em 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><strong>$<span>" + String.Format("{0:0.00}", priceExclGst) + "</span></strong></td></tr>"); stringBuilder.Append("<tr><td colspan='2'> </td><td colspan='3' width='100' style='padding:0.5em 0.25em;border-bottom:1px solid #c4c4c4'>GST</td>"); stringBuilder.Append("<td width='100' style='padding:0.5em 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><strong>$<span>" + String.Format("{0:0.00}", gst) + "</span></strong></td></tr>"); stringBuilder.Append("<tr><td colspan='2'> </td><td colspan='3' width='100' style='padding:0.5em 0.25em;border-bottom:1px solid #c4c4c4'>Total Price Inc.GST</td>"); stringBuilder.Append("<td width='100' style='padding:0.5em 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><strong>$<span>" + String.Format("{0:0.00}", priceIncGst) + "</span></strong></td></tr>"); stringBuilder.Append("<tr><td colspan='2'> </td><td colspan='3' width='100' style='padding:0.5em 0.25em;border-bottom:1px solid #c4c4c4'>Total Discount Earned</td>"); stringBuilder.Append("<td width='100' style='padding:0.5em 0.25em;border-bottom:1px solid #c4c4c4;text-align:right'><strong>$<span>" + String.Format("{0:0.00}", discount) + "</span></strong></td></tr>"); stringBuilder.Append("</tfoot></table></td></tr>"); stringBuilder.Append("<tr><td style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545'> </td></tr>"); stringBuilder.Append("<tr><td style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545;text-align:center;border-bottom:1px solid #d3d3d3'><p style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#45659d;margin:12px 20px 10px 20px;text-decoration:none'>BSB: </p><p style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#45659d;margin:12px 20px 10px 20px;text-decoration:none'>Account Number: </p><p style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#45659d;margin:12px 20px 10px 20px;text-decoration:none'>Account Name: </p></td></tr>"); stringBuilder.Append("<tr><td style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545;text-align:center;'><p style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#45659d;margin:12px 20px 10px 20px;text-decoration:none'>Diclaimer</p></td></tr>"); stringBuilder.Append("<tr><td style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545;text-align:center;border-bottom:1px solid #d3d3d3'><p style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#45659d;margin:12px 20px 10px 20px;text-decoration:none'>xxxxxx</p></td></tr>"); stringBuilder.Append("<tr><td style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545;background:#f6f4ef;text-align:center;border-bottom:1px solid #d3d3d3'><p style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#45659d;margin:12px 20px 10px 20px;text-decoration:none'><a style='color:#454545;text-decoration:none' target='_blank'><strong>https://XXXXXXXX</strong></a></p></td></tr>"); stringBuilder.Append("</tbody></table></td></tr>"); stringBuilder.Append("<tr><td style='font:12px/1.5 Arial,Helvetica,sans-serif;color:#454545'> </td></tr>"); stringBuilder.Append("</tbody></table></div>"); string emailBody = stringBuilder.ToString(); share.SendEmail("*****@*****.**", currentUser.Email, "test", emailBody, "", "", true); foreach (var si in cart.ShoppingItems) { si.Status = "1"; si.Product = null; si.ShoppingCartId = cart.Id; } _shoppingItemDataRepository.UpdateRange(cart.ShoppingItems.ToList()); await _shoppingItemDataRepository.SaveChangesAsync(); cart.Status = "1"; _shoppingCartDataRepository.Update(cart); await _shoppingCartDataRepository.SaveChangesAsync(); ShoppingCart sc = new ShoppingCart() { TotalItems = 0, OriginalPrice = 0, TotalPrice = 0, UserId = order.UserId, Status = "0", PaymentMethod = "onaccount" }; _shoppingCartDataRepository.Create(sc); await _shoppingCartDataRepository.SaveChangesAsync(); return(new ApiResponse() { Status = "success", Message = "Successfully create order" }); } catch (Exception ex) { return(new ApiResponse() { Status = "fail", Message = ex.Message }); } }
public async Task <IActionResult> UploadProducts() { try { var httpRequest = HttpContext.Request; if (httpRequest.Form.Files.Count > 0) { var uploadFile = httpRequest.Form.Files[0]; // get the uploaded file if (uploadFile != null && uploadFile.Length > 0) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "ImportProducts.xlsx"); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } using (var stream = new FileStream(path, FileMode.Create)) { uploadFile.CopyTo(stream); stream.Close(); } FileInfo file = new FileInfo(path); using (ExcelPackage package = new ExcelPackage(file)) { ExcelWorksheet workSheet = package.Workbook.Worksheets["Trojan Product items as at 2407"]; int totalRows = workSheet.Dimension.Rows; List <Product> productList = new List <Product>(); List <Product> updateProductList = new List <Product>(); for (int i = 2; i <= totalRows; i++) { if (workSheet.Cells[i, 2].Value != null) { if (_productDataRepository.Queryable.Where(x => x.Name == workSheet.Cells[i, 3].Value.ToString()).Count() < 1) { productList.Add(new Product() { ItemCode = workSheet.Cells[i, 2].Value == null ? "" : workSheet.Cells[i, 2].Value.ToString(), Name = workSheet.Cells[i, 3].Value == null ? "" : workSheet.Cells[i, 3].Value.ToString(), Category = workSheet.Cells[i, 4].Value == null ? "" : workSheet.Cells[i, 4].Value.ToString().Trim().Replace(' ', '-'), OriginalPrice = workSheet.Cells[i, 6].Value == null ? 0 : double.Parse(workSheet.Cells[i, 6].Value.ToString().Replace("$", "").Trim()), AgentPrice = workSheet.Cells[i, 7].Value == null ? 0 : double.Parse(workSheet.Cells[i, 7].Value.ToString().Replace("$", "").Trim()), WholesalerPrice = workSheet.Cells[i, 8].Value == null ? 0 : double.Parse(workSheet.Cells[i, 8].Value.ToString().Replace("$", "").Trim()), PrepaymentDiscount = workSheet.Cells[i, 9].Value == null ? 0 : double.Parse(workSheet.Cells[i, 9].Value.ToString().Replace("$", "").Trim()), Status = workSheet.Cells[i, 10].Value == null ? "" : workSheet.Cells[i, 10].Value.ToString() }); } else { var product = _productDataRepository.Queryable.Where(x => x.Name == workSheet.Cells[i, 3].Value.ToString()).FirstOrDefault(); product.ItemCode = workSheet.Cells[i, 2].Value == null ? "" : workSheet.Cells[i, 2].Value.ToString(); product.Name = workSheet.Cells[i, 3].Value == null ? "" : workSheet.Cells[i, 3].Value.ToString(); product.Category = workSheet.Cells[i, 4].Value == null ? "" : workSheet.Cells[i, 4].Value.ToString().Trim().Replace(' ', '-'); product.OriginalPrice = workSheet.Cells[i, 6].Value == null ? 0 : double.Parse(workSheet.Cells[i, 6].Value.ToString().Replace("$", "").Trim()); product.AgentPrice = workSheet.Cells[i, 7].Value == null ? 0 : double.Parse(workSheet.Cells[i, 7].Value.ToString().Replace("$", "").Trim()); product.WholesalerPrice = workSheet.Cells[i, 8].Value == null ? 0 : double.Parse(workSheet.Cells[i, 8].Value.ToString().Replace("$", "").Trim()); product.PrepaymentDiscount = workSheet.Cells[i, 9].Value == null ? 0 : double.Parse(workSheet.Cells[i, 9].Value.ToString().Replace("$", "").Trim()); product.Status = workSheet.Cells[i, 10].Value == null ? "" : workSheet.Cells[i, 10].Value.ToString(); _productDataRepository.Update(product); await _productDataRepository.SaveChangesAsync(); } } } if (productList.Count > 0) { _productDataRepository.CreateRange(productList); await _productDataRepository.SaveChangesAsync(); } for (int i = 2; i <= totalRows; i++) { if (workSheet.Cells[i, 2].Value != null) { if (_packagingListDataRepository.Queryable.Where(x => x.ProductId == _productDataRepository.Queryable.Where(y => y.Name == workSheet.Cells[i, 3].Value.ToString()).FirstOrDefault().Id).Count() < 1) { List <PackagingList> PackageNames = new List <PackagingList>(); string PackageName = workSheet.Cells[i, 5].Value == null ? "" : workSheet.Cells[i, 5].Value.ToString(); int productId = _productDataRepository.Queryable.Where(x => x.Name == workSheet.Cells[i, 3].Value.ToString()).FirstOrDefault().Id; if (PackageName.ToLower().Contains("op")) { PackageNames.Add(new PackagingList() { ProductId = productId, PackageName = "OP" }); } if (PackageName.ToLower().Contains("pp")) { PackageNames.Add(new PackagingList() { ProductId = productId, PackageName = "PP" }); } _packagingListDataRepository.CreateRange(PackageNames); await _packagingListDataRepository.SaveChangesAsync(); } else { var updatePackageNames = _packagingListDataRepository.Queryable.Where(x => x.ProductId == _productDataRepository.Queryable.Where(y => y.Name == workSheet.Cells[i, 3].Value.ToString()).FirstOrDefault().Id).FirstOrDefault(); string PackageName = workSheet.Cells[i, 5].Value == null ? "" : workSheet.Cells[i, 5].Value.ToString(); int productId = _productDataRepository.Queryable.Where(x => x.Name == workSheet.Cells[i, 3].Value.ToString()).FirstOrDefault().Id; if (PackageName.ToLower().Contains("op")) { updatePackageNames.ProductId = productId; updatePackageNames.PackageName = "OP"; } else if (PackageName.ToLower().Contains("pp")) { updatePackageNames.ProductId = productId; updatePackageNames.PackageName = "PP"; } else { _packagingListDataRepository.Delete(updatePackageNames); await _packagingListDataRepository.SaveChangesAsync(); } _packagingListDataRepository.Update(updatePackageNames); await _packagingListDataRepository.SaveChangesAsync(); } } } package.Stream.Close(); package.Dispose(); } return(Ok(new ApiResponse { Status = "success", Message = "Products uploaded." })); } } return(Ok(new ApiResponse { Status = "fail", Message = "Upload file is empty" })); } catch (Exception ex) { return(Ok(new ApiResponse { Status = "fail", Message = ex.Message })); } }