public async Task <IActionResult> SyncOrderPayments() { var errorList = new List <string>(); try { if (_db.Connection.State == System.Data.ConnectionState.Closed) { await _db.Connection.OpenAsync(); } var query = new OrderQueries(_db); var orders = await query.GetAllOrderPayments(); foreach (var order in orders) { try { var found = _context.OrderPayment.FirstOrDefault(o => o.OrderId == int.Parse(order._pos_payment_order_id.ToString()) && o.PaymentAmount == decimal.Parse(order._pos_payment_amount.ToString()) && o.AuthCode == order._pos_payment_AuthCode.ToString()); if (found == null) { var newOrder = new OrderPayment { CreatedByUserId = order.post_author.ToString(), CreatedDate = order.post_date, CreditCard = order._pos_payment_lastFour, OrderId = int.Parse(order._pos_payment_order_id.ToString()), PaymentAmount = decimal.Parse(order._pos_payment_amount), PaymentDate = order.post_date, PaymentTypeId = int.Parse(order._pos_payment_paymentType_id.ToString()), AuthCode = order._pos_payment_AuthCode, Notes = order._pos_payment_comment, ChequeNo = order._pos_payment_chequeNo }; newOrder.PaymentType = null; await _context.OrderPayment.AddAsync(newOrder); await _context.SaveChangesAsync(); } else { // await _context.SaveChangesAsync(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } _db.Connection.Close(); } catch (Exception ex) { errorList.Add("order taxes:" + ex.ToString()); } return(Ok(errorList)); }
public List <DtoOrder> GetAvailableOrders(int storeId) { try { EnsureArg.IsGt(storeId, 0, nameof(storeId)); } catch (Exception ex) { throw new BadRequest(ex); } var response = CacheManager.GetHashs <DtoOrder>(CacheKey.StoreOrders, storeId.ToString()); var removeItem = new List <string>(); foreach (var item in response) { var relativeTimespace = item.Value.RequestedOn - DateTime.Now; if (relativeTimespace > TimeSpan.FromMinutes(ORDER_RESPONSE_EXPIRATION_TIME)) { CacheManager.DeleteHash(CacheKey.StoreOrders, storeId.ToString(), item.Key); removeItem.Add(item.Key); } } var result = response.Where(i => !removeItem.Contains(i.Key)).Select(i => i.Value).ToList(); var ordered = OrderQueries.GetOrderIn(result.Select(i => i.Id).ToList()).OrderBy(i => i.RequestedOn); return(ordered.Select(i => CheckOrder(i)).ToList()); }
public void Remove(Guid id) { var entity = _context.Order.Find(OrderQueries.GetOrderById(id)); _context.Order.Remove(entity); _context.SaveChanges(); }
public DtoOrder AddResponse(int orderId, int drugStoreId, DtoSkuReply skuReplay) { try { EnsureArg.IsGt(orderId, 0, nameof(orderId)); } catch (Exception ex) { throw new BadRequest(ex); } var order = OrderQueries.GetOrder(orderId); var drugstore = StoreDomain.Get(drugStoreId); if (order.Responses != null) { order.Responses = new List <DtoOrderResponse>(); var response = new DtoOrderResponse() { DrugStore = drugstore, Accepted = false }; OrderQueries.CreateResponse(ref response, orderId); order.Responses.Add(response); } return(CheckOrder(order)); }
public DtoOrder MakeOrderRequest(int orderId) { try { EnsureArg.IsGt(orderId, 0, nameof(orderId)); } catch (Exception ex) { throw new BadRequest(ex); } var order = OrderQueries.GetOrder(orderId); order.RequestedOn = DateTime.Now; OrderQueries.Update(ref order); var stores = StoreDomain.GetNearStore(order.AddressToShip); order.RequestedStores = stores; foreach (var store in stores) { OrderQueries.SetStoreOnOrder(order.Id, store.Id); CacheManager.SetHash(CacheKey.StoreOrders, store.Id.ToString(), order.Id.ToString(), order); } return(CheckOrder(order)); }
public DtoOrder AddSku(int orderId, DtoSku skuRequest) { try { EnsureArg.IsNotNull(skuRequest, nameof(skuRequest)); EnsureArg.IsGt(orderId, 0, nameof(orderId)); } catch (Exception ex) { throw new BadRequest(ex); } var skus = OrderQueries.GetRequestedSkus(orderId); var dbsku = skus.Where(i => i.Id == skuRequest.Id).FirstOrDefault(); DtoOrder dtoOrder = null; if (dbsku == null) { dtoOrder = OrderQueries.AddSku(orderId, skuRequest.Id, skuRequest.Quantity.Value); } else { dtoOrder = OrderQueries.UpdateSku(orderId, dbsku.OrderSkuId.Value, skuRequest.Quantity.Value); } return(CheckOrder(dtoOrder)); }
public async Task <IActionResult> SyncOrderLineItems() { var errorList = new List <string>(); try { if (_db.Connection.State == System.Data.ConnectionState.Closed) { await _db.Connection.OpenAsync(); } var query = new OrderQueries(_db); var orders = await query.GetAllOrderDetails(); foreach (var order in orders) { try { var orderId = int.Parse(order.order_id.ToString()); var productId = int.Parse(order._product_id); if (orderId >= 75746 || !_context.Product.Where(o => o.ProductId == productId).Any() || !_context.Order.Where(o => o.OrderId == orderId).Any()) { continue; } var newOrder = new OrderDetail { Amount = decimal.Parse(order._qty), ProductId = productId, SubTotal = string.IsNullOrEmpty(order._line_subtotal) ? 0 : decimal.Parse(order._line_subtotal), Total = string.IsNullOrEmpty(order._line_total) ? 0 : decimal.Parse(order._line_total), UnitPrice = string.IsNullOrEmpty(order._line_price) ? 0 : decimal.Parse(order._line_price), OrderId = orderId }; newOrder.Product = null; newOrder.DiscountAmount = 0; newOrder.TotalDiscount = 0; await _context.OrderDetail.AddAsync(newOrder); await _context.SaveChangesAsync(); } catch (Exception ex) { errorList.Add("order line items:" + ex.ToString()); } } _db.Connection.Close(); } catch (Exception ex) { errorList.Add("order line items:" + ex.ToString()); } return(Ok(errorList)); }
public IQueryable <TEntity> Set <TEntity>() where TEntity : class { if (typeof(TEntity) == typeof(Customer)) { return((IQueryable <TEntity>)Customers.AsQueryable()); } if (typeof(TEntity) == typeof(Employee)) { return((IQueryable <TEntity>)Employees.AsQueryable()); } if (typeof(TEntity) == typeof(Order)) { return((IQueryable <TEntity>)Orders.AsQueryable()); } if (typeof(TEntity) == typeof(OrderDetail)) { return((IQueryable <TEntity>)OrderDetails.AsQueryable()); } if (typeof(TEntity) == typeof(Product)) { return((IQueryable <TEntity>)Products.AsQueryable()); } if (typeof(TEntity) == typeof(CustomerQuery)) { return((IQueryable <TEntity>)CustomerQueries.AsQueryable()); } if (typeof(TEntity) == typeof(OrderQuery)) { return((IQueryable <TEntity>)OrderQueries.AsQueryable()); } if (typeof(TEntity) == typeof(ProductQuery)) { return((IQueryable <TEntity>)ProductQueries.AsQueryable()); } if (typeof(TEntity) == typeof(ProductView)) { return((IQueryable <TEntity>)ProductViews.AsQueryable()); } if (typeof(TEntity) == typeof(CustomerQueryWithQueryFilter)) { return((IQueryable <TEntity>)CustomerQueriesWithQueryFilter.AsQueryable()); } throw new InvalidOperationException("Invalid entity type: " + typeof(TEntity)); }
public DtoOrder GetIncompletLastOrder(DtoClient client) { var order = OrderQueries.GetLastIncompletedOrder(client.Id); if (order == null) { return(GenerateNewOrder(client)); } return(CheckOrder(order)); }
public Order GetDraftById(int id) { return(_context.Orders .Include(o => o.MerchandiseList) .ThenInclude(m => m.Book) .Include(o => o.ExchangedMerchandise) .ThenInclude(m => m.Book) .Include(o => o.CreditCardList) .Include(o => o.CouponAppliedList) .Include(o => o.DeliveryAddress) .Include(o => o.BillingAddress) .FirstOrDefault(OrderQueries.GetDraftById(id))); }
public OrderMerchandise GetMerchandiseByOrderIdAndBookId(int bookId, int orderId = 0) { OrderMerchandise result = null; var _order = _context.Orders .Include(o => o.MerchandiseList) .ThenInclude(m => m.Book) .FirstOrDefault(OrderQueries.GetById(orderId)); if (_order != null) { result = _order.MerchandiseList.FirstOrDefault(m => m.Book.Id == bookId); } return(result); }
public List <Order> GetByCustomerId(int id) { return(_context.Orders .AsNoTracking() .Where(OrderQueries.GetByCustomerId(id)) .Include(o => o.MerchandiseList) .ThenInclude(m => m.Book) .Include(o => o.ExchangedMerchandise) .ThenInclude(m => m.Book) .Include(o => o.CreditCardList) .Include(o => o.CouponAppliedList) .Include(o => o.DeliveryAddress) .Include(o => o.BillingAddress) .ToList()); }
public List <Order> GetAllByPeriod(DateTime initialDate, DateTime finalDate) { return(_context.Orders .Where(OrderQueries.GetByPeriod(initialDate, finalDate)) .Include(o => o.MerchandiseList) .ThenInclude(m => m.Book) .Include(o => o.ExchangedMerchandise) .ThenInclude(m => m.Book) .Include(o => o.CreditCardList) .Include(o => o.CouponAppliedList) .Include(o => o.DeliveryAddress) .Include(o => o.BillingAddress) .AsNoTracking() .ToList()); }
public DtoOrder SetShippping(string clientToken, int addressId) { try { EnsureArg.IsNotNullOrEmpty(clientToken, nameof(clientToken)); EnsureArg.IsGt(addressId, 0, nameof(addressId)); } catch (Exception ex) { throw new BadRequest(ex); } var client = ClientQueries.GetClient(clientToken); var order = GetIncompletLastOrder(client); order.AddressToShip = client.Addresses.Where(i => i.Id == addressId).SingleOrDefault(); OrderQueries.Update(ref order); return(CheckOrder(order)); }
public ActionResult ViewGraphOfOfficeUnitsPartial(int officeId) { var model = new OrderQueries().GetStocksLeftByOffice(officeId); return(PartialView("_ViewGraphOfOfficeUnitsPartial", model)); }
public ActionResult ViewGraphOfOffice(int officeId) { var model = new OrderQueries().GetStocksLeftByOffice(officeId); return(View(model)); }
/// <summary> /// input/output for the process of displaying an order's details with all /// the validation taking place along the way and finally displaying /// the details of the order meeting the input parameters. /// </summary> public void DisplayOrderDetails() { OrderCreation createOrder = new OrderCreation(); // for Validation method OrderQueries checkOrder = new OrderQueries(); int orderID; // get and display orders to pick from var orders = checkOrder.GetOrders(); Console.WriteLine("ID\tTimestamp"); foreach (var o in orders) { Console.WriteLine($"{o.OrderID}\t{o.Timestamp}"); } Console.WriteLine("Please enter the ID of the order you would like to see"); do { string input = Console.ReadLine(); if (input == "cancel") { return; } // check if input is an int while (!createOrder.IsValidNum(input)) { Console.WriteLine("Invalid order ID number, please enter another."); input = Console.ReadLine(); if (input == "cancel") { return; } } int id = createOrder.StringToInt(input); // check if there is an order with the given ID if (checkOrder.IsValidOrderID(id)) { orderID = id; } else { Console.WriteLine("There is no order with this ID, please enter another."); orderID = 0; } } while (orderID == 0); var orderDetails = checkOrder.GetOrderDetails(orderID); // get all the order details and display them to console Console.WriteLine("Customer\tStore Location\t\tProduct\t\tQuantity\tTotal\tTimestamp"); foreach (var o in orderDetails) { double price = o.Product.Price * o.Quantity; Console.WriteLine($"{o.Customer.FirstName} {o.Customer.LastName}\t" + $"{o.Product.Store.Location}\t\t{o.Product.ProductName}\t{o.Quantity}" + $"\t\t${price}\t{o.Timestamp}"); } Console.WriteLine("Press enter to return to the menu"); Console.ReadLine(); }
// GET: Orders public ActionResult Index() { var model = new OrderQueries().GetAllOrders(); return(View(model)); }
public ActionResult ViewRemainingPerOffice(int officeId) { var model = new OrderQueries().OrdersHistoryPerOffice(); return(View(model)); }
public DtoOrder GetRealTimeOrder(int orderId) { var order = OrderQueries.GetOrder(orderId); return(CheckOrder(order)); }
public DtoOrder CheckOrder(DtoOrder order) { try { EnsureArg.IsNotNull(order, nameof(order)); } catch (Exception ex) { throw new BadRequest(ex); } if (order.Id == 0) { OrderQueries.Create(ref order); } if (order.AddressToShip == null) { order.AddressToShip = order.Client?.Addresses?.FirstOrDefault(); OrderQueries.Update(ref order); } if (order.RequestedStores == null) { order.RequestedStores = StoreDomain.GetNearStore(order.AddressToShip); } if (order.SkusRequesteds?.Count() > 0) { foreach (var sku in order.SkusRequesteds) { sku.ProductReference = ProductDomain.GetProductBySku(sku.Id); } } return(order); // TODO Delivery //if (order.AddressToShip != null && order.RequestedStores?.Count() > 0) //{ // foreach (var store in order.RequestedStores) // { // var clientLocation = new GeoCoordinate(order.AddressToShip.Latitude.Value, order.AddressToShip.Longitude.Value); // var storeLocation = new GeoCoordinate(store.Address.Latitude.Value, store.Address.Longitude.Value); // store.Proximity = clientLocation.GetDistanceTo(storeLocation); // if (store.AvaibleDeliveries?.Count > 0) // { // var maxdistance = store.AvaibleDeliveries.Max(i => i.MaxDistance); // var safeDelivery = store.AvaibleDeliveries.Where(i => i.MaxDistance == maxdistance).FirstOrDefault(); // var removeDeliverys = new List<DtoDelivery>(); // foreach (var delivery in store.AvaibleDeliveries) // { // if (store.Proximity > delivery.MaxDistance) // removeDeliverys.Add(delivery); // } // var deliveryMethod = store.AvaibleDeliveries // .Where(i => !removeDeliverys.Contains(i)) // .OrderBy(i => i.MaxDistance).FirstOrDefault(); // if (deliveryMethod == null) // store.Delivery = safeDelivery; // else // store.Delivery = deliveryMethod; // } // } //} }
public async Task <IActionResult> SyncOrderTaxes() { var errorList = new List <string>(); try { if (_db.Connection.State == System.Data.ConnectionState.Closed) { await _db.Connection.OpenAsync(); } var query = new OrderQueries(_db); var orders = await query.GetAllOrders(); foreach (var order in orders) { decimal taxGst = 0; if (!string.IsNullOrEmpty(order._pos_sale_tax_GST)) { decimal.TryParse(order._pos_sale_tax_GST, out taxGst); } decimal taxPst = 0; if (!string.IsNullOrEmpty(order._pos_sale_tax_PST)) { decimal.TryParse(order._pos_sale_tax_PST, out taxPst); } var found = await _context.OrderTax.FindAsync(int.Parse(order.id.ToString())); if (found == null) { if (taxPst > 0) { var orderTaxGst = new OrderTax { OrderId = int.Parse(order.id.ToString()), TaxAmount = taxGst, TaxId = 1 }; await _context.OrderTax.AddAsync(orderTaxGst); } if (taxPst > 0) { var orderTaxPst = new OrderTax { OrderId = int.Parse(order.id.ToString()), TaxAmount = taxPst, TaxId = 2 }; await _context.OrderTax.AddAsync(orderTaxPst); } await _context.SaveChangesAsync(); } else { // await _context.SaveChangesAsync(); } } _db.Connection.Close(); } catch (Exception ex) { errorList.Add("order taxes:" + ex.ToString()); } return(Ok(errorList)); }
public async Task <IActionResult> SyncOrders() { var errorList = new List <string>(); try { if (_db.Connection.State == System.Data.ConnectionState.Closed) { await _db.Connection.OpenAsync(); } var query = new OrderQueries(_db); var orders = await query.GetAllOrders(); foreach (var order in orders) { //var limit = 0; //int.TryParse(customer._pos_customer_accountlimit, out limit); int customerId = 0; if (!string.IsNullOrEmpty(order._pos_sale_customer_id)) { int.TryParse(order._pos_sale_customer_id, out customerId); } decimal discount = 0; if (!string.IsNullOrEmpty(order._pos_sale_discount)) { decimal.TryParse(order._pos_sale_discount, out discount); } decimal total = 0; if (!string.IsNullOrEmpty(order._pos_sale_total)) { decimal.TryParse(order._pos_sale_total, out total); } decimal subtotal = 0; if (!string.IsNullOrEmpty(order._pos_sale_subtotal)) { decimal.TryParse(order._pos_sale_subtotal, out subtotal); } var location = 1; if (!string.IsNullOrEmpty(order._pos_location_name)) { location = order._pos_location_name.Equals("abbotsford", StringComparison.InvariantCultureIgnoreCase) ? 2 : 1; } var found = await _context.Order.FindAsync(int.Parse(order.id.ToString())); if (found == null) { var newOrder = new Order { CreatedByUserId = order._pos_sale_user, CreatedDate = order.post_date, CustomerId = customerId, TotalDiscount = discount, LocationId = location, Notes = order._pos_sale_note, OrderDate = order.post_date, OriginalOrderId = 0,// order._pos_linkedInvoice, PoNumber = order._pos_po_number, PstNumber = "", Status = order._pos_status, SubTotal = subtotal, OrderId = int.Parse(order.id.ToString()), Total = total }; newOrder.Customer = null; newOrder.Location = null; await _context.Order.AddAsync(newOrder); await _context.SaveChangesAsync(); } else { // await _context.SaveChangesAsync(); } } _db.Connection.Close(); } catch (Exception ex) { errorList.Add("order taxes:" + ex.ToString()); } return(Ok(errorList)); }
public async Task <ActionResult> DailyReport([FromQuery] PagingParams pagingParams, [FromQuery] DateTime fromDate, [FromQuery] DateTime toDate) { return(await OrderQueries.DailyReport(pagingParams, fromDate, toDate)); }
public OrderController(IOrderService iOrderService, OrderQueries orderQueries, IResponseMessages responsMessages) { IOrderService = iOrderService; OrderQueries = orderQueries; ResponsMessages = responsMessages as ResponseMessages; }
public async Task <ActionResult> Get(Guid id) { return(await OrderQueries.Get(id)); }
public async Task <ActionResult> Search([FromQuery] PagingParams pagingParams, [FromQuery] string filter = null) { return(await OrderQueries.Search(pagingParams, filter)); }