private BillingDocument showOrder(Order id) { var orderDB = new DBOrder(); List <OrderLine> list = orderDB.getOrder(id.id); List <ShoppingCartItem> cartItems = new List <ShoppingCartItem>(); var cartSum = 0; foreach (var item in list) { cartItems.Add(new ShoppingCartItem(item.product, item.quantity)); cartSum += item.product.price * item.quantity; } ; var cart = new ShoppingCart(id.customerid) { shoppingCartItems = cartItems, sum = cartSum }; var billingDoc = new BillingDocument() { order = id, customer = (Customer)Session["LoggedInUser"], shoppingcart = cart, sum = cart.sum, exmva = cart.sum * 0.8, mva = cart.sum * 0.2 }; return(billingDoc); }
public ActionResult Frontpage() { DBOrder order = new DBOrder(); List<Product> topFive = order.getMostSold(); return View(topFive); }
private static void PrintReceiptForTransaction(DBOrder order) { LogService(order.clientName + Environment.NewLine + order.orderXtraDesc + Environment.NewLine + order.clientPOS + Environment.NewLine + order.clientStore + Environment.NewLine); DiskBoiaDocument recordDoc = new DiskBoiaDocument(order); recordDoc.DocumentName = "Pedido DiskBoia #" + order.orderId; recordDoc.PrintPage += new PrintPageEventHandler(PrintReceiptPage); // function below recordDoc.PrintController = new StandardPrintController(); // hides status dialog popup // Comment if debugging PrinterSettings ps = new PrinterSettings(); ps.PrinterName = printerName; recordDoc.PrinterSettings = ps; recordDoc.Print(); // -------------------------------------- // Uncomment if debugging - shows dialog instead /*PrintPreviewDialog printPrvDlg = new PrintPreviewDialog(); * printPrvDlg.Document = recordDoc; * printPrvDlg.Width = 1200; * printPrvDlg.Height = 800; * printPrvDlg.ShowDialog();*/ // -------------------------------------- recordDoc.Dispose(); }
public ActionResult Frontpage() { DBOrder order = new DBOrder(); List <Product> topFive = order.getMostSold(); return(View(topFive)); }
public ActionResult LogOut() { DBOrder order = new DBOrder(); List<Product> topFive = order.getMostSold(); Session["loggedInUser"] = null; return RedirectToAction("Frontpage","Main",topFive); }
public ActionResult LogOut() { DBOrder order = new DBOrder(); List <Product> topFive = order.getMostSold(); Session["loggedInUser"] = null; return(RedirectToAction("Frontpage", "Main", topFive)); }
private bool Update() { return(DBOrder.Update( this.orderID, this.siteID, this.orderGuid, this.orderCode, this.orderSubtotal, this.orderShipping, this.orderDiscount, this.orderTax, this.orderTotal, this.currencyCode, this.couponCode, this.orderNote, this.billingFirstName, this.billingLastName, this.billingEmail, this.billingAddress, this.billingPhone, this.billingMobile, this.billingFax, this.billingStreet, this.billingWard, this.billingDistrictGuid, this.billingProvinceGuid, this.billingCountryGuid, this.shippingFirstName, this.shippingLastName, this.shippingEmail, this.shippingAddress, this.shippingPhone, this.shippingMobile, this.shippingFax, this.shippingWard, this.shippingStreet, this.shippingDistrictGuid, this.shippingProvinceGuid, this.shippingCountryGuid, this.orderStatus, this.paymentStatus, this.shippingStatus, this.shippingMethod, this.paymentMethod, this.invoiceCompanyName, this.invoiceCompanyAddress, this.invoiceCompanyTaxCode, this.customValuesXml, this.stateID, this.userGuid, this.createdFromIP, this.createdBy, this.createdUtc, this.isDeleted, this.userPoint, this.userPointDiscount)); }
/// <summary> /// Creates two /// </summary> /// <param name="genericType"></param> public void Remove(int id) { DBOrder order = context.DBOrders.FirstOrDefault(order => order.ID == id); if (order is not null) { context.Remove(order); context.SaveChanges(); } }
public void Init(DBOrder _order) { order = _order; state = new CLStateUpdator <State>(); state.Init( OnCheckState, OnChangeState, OnUpdateState ); }
private void GetOrder(int orderID) { using (IDataReader reader = DBOrder.GetOne(orderID)) { if (reader.Read()) { GetOrderFromReader(reader, this); } } }
/// <summary> /// Creates two /// </summary> /// <param name="genericType"></param> public void Remove(Order genericType) { DBOrder dbOrder = mapperOrder.Map(genericType); DBOrder order = context.DBOrders.ToList().Find(order => order.GetHashCode() == dbOrder.GetHashCode()); if (order is not null) { context.Remove(order); context.SaveChanges(); } }
public bool FinishOrder() { bool isAllOk = true; if (isAllOk) { DBOrder dbOrder = new DBOrder(); dbOrder.FinishOrder(currOrder); } return(isAllOk); }
public static Order GetOrderByCode(string orderCode) { Order order = null; using (IDataReader reader = DBOrder.GetOneByCode(orderCode)) { if (reader.Read()) { order = new Order(); GetOrderFromReader(reader, order); } } return(order); }
public static int GetCount( int siteID, int stateID, int orderStatus, int paymentMethod, int shippingMethod, DateTime?fromDate, DateTime?toDate, decimal?fromOrderTotal, decimal?toOrderTotal, Guid?userGuid, string keyword) { return(DBOrder.GetCount(siteID, stateID, orderStatus, paymentMethod, shippingMethod, fromDate, toDate, fromOrderTotal, toOrderTotal, userGuid, keyword)); }
public ActionResult viewOrderHistory() { var user = (Customer)Session["LoggedInUser"]; if (user == null) { return(RedirectToAction("Frontpage", "Home")); } var db = new DBOrder(); List <Order> list = db.getOrders(user.id); TempData["pview"] = "orderline"; TempData["list"] = list; return(View("PersonalSite", user)); }
public void update(Order existingType, Order updatedType) { DBOrder dbOrder = mapperOrder.Map(existingType); DBOrder order = context.DBOrders.ToList().Find(order => order.GetHashCode() == dbOrder.GetHashCode()); if (order is not null) { DBOrder updatedOrder = mapperOrder.Map(updatedType); order.DBCustomer = updatedOrder.DBCustomer; order.Pizzas = updatedOrder.Pizzas; order.DBStore = updatedOrder.DBStore; order.TimeStamp = updatedOrder.TimeStamp; order.PriceTotal = updatedOrder.PriceTotal; context.SaveChanges(); } }
static void AssignOrderRequest(FIFakeContext context, DBOrder order, bool giveDelay) { //Remove existing items first... var existOrderItemList = context.dbContext.GetList <DBOrderItem>().Where(x => x.orderUID == order.uid).ToList(); foreach (var item in existOrderItemList) { // Debug.LogWarning("Found existing item="+item.orderUID+" id="+item.uid); context.dbContext.Dispose <DBOrderItem>(item.uid); } if (existOrderItemList.Count > 0) { InsertDeleted(context, existOrderItemList.ToArray()); } int availableTypeCnt = UnityEngine.Random.Range(1, 4); var listOfAvailable = context.staticData.GetList <GDItemData>() .Where(x => { if (x.type.IsFlagSet(GDItemDataType.CustomerEat) && x.baseLv <= context.easy.UserInfo.userLv) { return(true); } return(false); }).ToList(); availableTypeCnt = System.Math.Min(availableTypeCnt, listOfAvailable.Count); for (int i = 0; i < availableTypeCnt; i++) { var itemData = context.dbContext.Create <DBOrderItem>(); itemData.orderUID = order.uid; int randNum = Random.Range(0, listOfAvailable.Count); itemData.itemID = listOfAvailable[randNum].id; itemData.itemCnt = Random.Range(listOfAvailable[randNum].baseReqMin, listOfAvailable[randNum].baseReqMax + 1); listOfAvailable.RemoveAt(randNum); InsertUpdated(context, itemData); } if (giveDelay == false) { order.waitStartedTime = CurrentTime - context.easy.GlobalInfo.orderRegenTime; } else { order.waitStartedTime = CurrentTime; } }
public string hentAlleOrdre() { var db = new DBOrder(); List <Order> alleOrdre = db.alleOrdre(); if (alleOrdre == null) { return(null); } var jsonSerializer = new JavaScriptSerializer(); jsonSerializer.MaxJsonLength = Int32.MaxValue; string json = jsonSerializer.Serialize(alleOrdre); return(json); }
public static List <Order> GetPage( int siteID, int stateID, int orderStatus, int paymentMethod, int shippingMethod, DateTime?fromDate, DateTime?toDate, decimal?fromOrderTotal, decimal?toOrderTotal, Guid?userGuid, string keyword, int pageNumber, int pageSize) { IDataReader reader = DBOrder.GetPage(siteID, stateID, orderStatus, paymentMethod, shippingMethod, fromDate, toDate, fromOrderTotal, toOrderTotal, userGuid, keyword, pageNumber, pageSize); return(LoadListFromReader(reader)); }
public ActionResult checkout(Order order) { RedirectToAction("viewShoppingCart"); if (order.id != 0) { return(View(showOrder(order))); } ViewBag.Empty = false; ShoppingCart cart = getCart(); if (cart == null) { ViewBag.Empty = true; return(View()); } var orderDB = new DBOrder(); var OrderId = orderDB.checkout(cart); var returnCustomer = (Customer)Session["LoggedInUser"]; returnCustomer.shoppingcart = new ShoppingCart(returnCustomer.id); Session["LoggedInUser"] = returnCustomer; return(View(new BillingDocument() { customer = returnCustomer, shoppingcart = cart, order = new Order() { id = OrderId, customerid = returnCustomer.id, orderdate = DateTime.Now }, sum = cart.sum, exmva = cart.sum * 0.8, mva = cart.sum * 0.2 })); }
public ActionResult ListProfile() { string epost = (string)Session["BrukerId"]; if (Session["LoggetInn"] != null) { bool loggetInn = (bool)Session["LoggetInn"]; if (loggetInn) { var db = new DBOrder(); List <Order> alleOrdere = db.hentOrderInnhold(epost); if (alleOrdere == null) { alleOrdere = new List <Order>(); return(View(alleOrdere)); } return(View(alleOrdere)); } } return(RedirectToAction("Index")); }
public Order Update(Order updatedType) { DBOrder dBOrder = mapperOrder.Map(updatedType, context); context.SaveChanges(); return(mapperOrder.Map(dBOrder)); /* * DBOrder dbOrder = mapperOrder.Map(existingType, context); * DBOrder order = context.DBOrders.ToList().Find(order => order.GetHashCode() == dbOrder.GetHashCode()); * if (order is not null) * { * DBOrder updatedOrder = mapperOrder.Map(updatedType, context); * order.DBCustomer = updatedOrder.DBCustomer; * order.Pizzas = updatedOrder.Pizzas; * order.DBStore = updatedOrder.DBStore; * order.TimeStamp = updatedOrder.TimeStamp; * order.PriceTotal = updatedOrder.PriceTotal; * context.SaveChanges(); * } */ }
private static Order DBMapping(DBOrder dbItem) { if (dbItem == null) return null; Order item = new Order(); item.OrderID = dbItem.OrderID; item.OrderGUID = dbItem.OrderGUID; item.CustomerID = dbItem.CustomerID; item.CustomerLanguageID = dbItem.CustomerLanguageID; item.CustomerTaxDisplayTypeID = dbItem.CustomerTaxDisplayTypeID; item.OrderSubtotalInclTax = dbItem.OrderSubtotalInclTax; item.OrderSubtotalExclTax = dbItem.OrderSubtotalExclTax; item.OrderShippingInclTax = dbItem.OrderShippingInclTax; item.OrderShippingExclTax = dbItem.OrderShippingExclTax; item.PaymentMethodAdditionalFeeInclTax = dbItem.PaymentMethodAdditionalFeeInclTax; item.PaymentMethodAdditionalFeeExclTax = dbItem.PaymentMethodAdditionalFeeExclTax; item.OrderTax = dbItem.OrderTax; item.OrderTotal = dbItem.OrderTotal; item.OrderDiscount = dbItem.OrderDiscount; item.OrderSubtotalInclTaxInCustomerCurrency = dbItem.OrderSubtotalInclTaxInCustomerCurrency; item.OrderSubtotalExclTaxInCustomerCurrency = dbItem.OrderSubtotalExclTaxInCustomerCurrency; item.OrderShippingInclTaxInCustomerCurrency = dbItem.OrderShippingInclTaxInCustomerCurrency; item.OrderShippingExclTaxInCustomerCurrency = dbItem.OrderShippingExclTaxInCustomerCurrency; item.PaymentMethodAdditionalFeeInclTaxInCustomerCurrency = dbItem.PaymentMethodAdditionalFeeInclTaxInCustomerCurrency; item.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency = dbItem.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency; item.OrderTaxInCustomerCurrency = dbItem.OrderTaxInCustomerCurrency; item.OrderTotalInCustomerCurrency = dbItem.OrderTotalInCustomerCurrency; item.CustomerCurrencyCode = dbItem.CustomerCurrencyCode; item.OrderWeight = dbItem.OrderWeight; item.AffiliateID = dbItem.AffiliateID; item.OrderStatusID = dbItem.OrderStatusID; item.AllowStoringCreditCardNumber = dbItem.AllowStoringCreditCardNumber; item.CardType = dbItem.CardType; item.CardName = dbItem.CardName; item.CardNumber = dbItem.CardNumber; item.MaskedCreditCardNumber = dbItem.MaskedCreditCardNumber; item.CardCVV2 = dbItem.CardCVV2; item.CardExpirationMonth = dbItem.CardExpirationMonth; item.CardExpirationYear = dbItem.CardExpirationYear; item.PaymentMethodID = dbItem.PaymentMethodID; item.PaymentMethodName = dbItem.PaymentMethodName; item.AuthorizationTransactionID = dbItem.AuthorizationTransactionID; item.AuthorizationTransactionCode = dbItem.AuthorizationTransactionCode; item.AuthorizationTransactionResult = dbItem.AuthorizationTransactionResult; item.CaptureTransactionID = dbItem.CaptureTransactionID; item.CaptureTransactionResult = dbItem.CaptureTransactionResult; item.PurchaseOrderNumber = dbItem.PurchaseOrderNumber; item.PaymentStatusID = dbItem.PaymentStatusID; item.BillingFirstName = dbItem.BillingFirstName; item.BillingLastName = dbItem.BillingLastName; item.BillingPhoneNumber = dbItem.BillingPhoneNumber; item.BillingEmail = dbItem.BillingEmail; item.BillingFaxNumber = dbItem.BillingFaxNumber; item.BillingCompany = dbItem.BillingCompany; item.BillingAddress1 = dbItem.BillingAddress1; item.BillingAddress2 = dbItem.BillingAddress2; item.BillingCity = dbItem.BillingCity; item.BillingStateProvince = dbItem.BillingStateProvince; item.BillingStateProvinceID = dbItem.BillingStateProvinceID; item.BillingZipPostalCode = dbItem.BillingZipPostalCode; item.BillingCountry = dbItem.BillingCountry; item.BillingCountryID = dbItem.BillingCountryID; item.ShippingStatusID = dbItem.ShippingStatusID; item.ShippingFirstName = dbItem.ShippingFirstName; item.ShippingLastName = dbItem.ShippingLastName; item.ShippingPhoneNumber = dbItem.ShippingPhoneNumber; item.ShippingEmail = dbItem.ShippingEmail; item.ShippingFaxNumber = dbItem.ShippingFaxNumber; item.ShippingCompany = dbItem.ShippingCompany; item.ShippingAddress1 = dbItem.ShippingAddress1; item.ShippingAddress2 = dbItem.ShippingAddress2; item.ShippingCity = dbItem.ShippingCity; item.ShippingStateProvince = dbItem.ShippingStateProvince; item.ShippingStateProvinceID = dbItem.ShippingStateProvinceID; item.ShippingZipPostalCode = dbItem.ShippingZipPostalCode; item.ShippingCountry = dbItem.ShippingCountry; item.ShippingCountryID = dbItem.ShippingCountryID; item.ShippingMethod = dbItem.ShippingMethod; item.ShippingRateComputationMethodID = dbItem.ShippingRateComputationMethodID; item.ShippedDate = dbItem.ShippedDate; item.Deleted = dbItem.Deleted; item.CreatedOn = dbItem.CreatedOn; return item; }
public static bool Delete( int orderID) { return(DBOrder.Delete( orderID)); }
public ActionResult viewOrderHistory() { var user = (Customer) Session["LoggedInUser"]; if (user == null) return RedirectToAction("Frontpage", "Home"); var db = new DBOrder(); List<Order> list = db.getOrders(user.id); TempData["pview"] = "orderline"; TempData["list"] = list; return View("PersonalSite", user); }
public void CreateOrderLineTable(BOrder currOrder) { DBOrder dbOrder = new DBOrder(); dbOrder.FinishOrder(currOrder); }
public DiskBoiaDocument(DBOrder order) { this.order = order; }
private static void PrintReceiptPage(object sender, PrintPageEventArgs e) { DBOrder order = ((DiskBoiaDocument)sender).order; float x = 5; float y = 5; float width = 270.0F; // max width I found through trial and error float height = 0F; Font drawFontArial14Bold = new Font("Arial Narrow", 14, FontStyle.Bold); Font drawFontArial16Bold = new Font("Arial Narrow", 16, FontStyle.Bold); Font drawFontArial10Regular = new Font("Arial Narrow", 10, FontStyle.Regular); Font drawFontArial10Bold = new Font("Arial Narrow", 10, FontStyle.Bold); Font drawFontArial10Italic = new Font("Arial Narrow", 10, FontStyle.Italic); SolidBrush drawBrush = new SolidBrush(Color.Black); // Set format of string. StringFormat drawFormatCenter = new StringFormat(); drawFormatCenter.Alignment = StringAlignment.Center; StringFormat drawFormatLeft = new StringFormat(); drawFormatLeft.Alignment = StringAlignment.Near; StringFormat drawFormatRight = new StringFormat(); drawFormatRight.Alignment = StringAlignment.Far; // Draw Header to printer. string text = ".:: DiskBoia ::."; e.Graphics.DrawString(text, drawFontArial16Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter); y += e.Graphics.MeasureString(text, drawFontArial16Bold).Height; // Draw separation line x = 5; text = new String('=', 40); e.Graphics.DrawString(text, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width + 14, height), drawFormatLeft); y += e.Graphics.MeasureString(text, drawFontArial10Bold).Height; // Draw order no. + timestamp + order taker text = "Pedido #" + order.orderId + ":"; e.Graphics.DrawString(text, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); x += e.Graphics.MeasureString(text, drawFontArial10Bold).Width; text = order.orderStamp + " - " + order.orderTaker; e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height; // Draw client name x = 5; text = "Cliente: "; e.Graphics.DrawString(text, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); x += e.Graphics.MeasureString(text, drawFontArial10Bold).Width; text = order.clientName; e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height; // Draw Delivery location x = 5; text = "Entrega: "; e.Graphics.DrawString(text, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); x += e.Graphics.MeasureString(text, drawFontArial10Bold).Width; text = order.deliveryPOS + "@" + order.deliveryStore; e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height; // Draw separation line x = 5; text = new String('=', 40); e.Graphics.DrawString(text, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width + 12, height), drawFormatLeft); y += e.Graphics.MeasureString(text, drawFontArial10Bold).Height; // Draw main dish price list with side dishes x = 5; decimal total = 0; decimal discount = 0; foreach (Dish dish in order.dishes) { total += Convert.ToDecimal(dish.dishVal, CultureInfo.InvariantCulture); // Draw main dish + main dish price e.Graphics.DrawString(dish.itemAbbr, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); text = "R$ " + dish.dishVal.Replace(".", ","); e.Graphics.DrawString(text, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatRight); y += e.Graphics.MeasureString(text, drawFontArial10Bold).Height; // Draw side dishes x = 10; foreach (sideDish side in dish.orderSides) { discount += Convert.ToDecimal(side.sideVal, CultureInfo.InvariantCulture); // draw side dish abbr + side dish value e.Graphics.DrawString(side.sideAbbr, drawFontArial10Italic, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); text = "R$ " + side.sideVal.Replace(".", ","); e.Graphics.DrawString(text, drawFontArial10Italic, drawBrush, // subtract 5 from rect width to align R$ values vertically new RectangleF(x, y, width - 5, height), drawFormatRight); y += e.Graphics.MeasureString(text, drawFontArial10Italic).Height; } // reset horz. position x = 5; } // Draw extra, if any decimal xtra = Convert.ToDecimal(order.orderXtraVal, CultureInfo.InvariantCulture); if (xtra > 0) { total += xtra; text = "*Extra: "; e.Graphics.DrawString(text, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); x += e.Graphics.MeasureString(text, drawFontArial10Bold).Width; e.Graphics.DrawString(order.orderXtraDesc, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); x = 5; text = "R$ " + order.orderXtraVal.ToString().Replace(".", ","); e.Graphics.DrawString(text, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatRight); y += e.Graphics.MeasureString(text, drawFontArial10Bold).Height; } // draw subtotal text = "SubTotal: "; e.Graphics.DrawString(text, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); text = "R$ " + (total + discount).ToString().Replace(".", ","); e.Graphics.DrawString(text, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatRight); y += e.Graphics.MeasureString(text, drawFontArial10Bold).Height; // draw discount, if > 0: if (discount > 0) { text = "Desconto: "; e.Graphics.DrawString(text, drawFontArial10Italic, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); text = "R$ " + discount.ToString().Replace(".", ","); e.Graphics.DrawString(text, drawFontArial10Italic, drawBrush, new RectangleF(x, y, width, height), drawFormatRight); y += e.Graphics.MeasureString(text, drawFontArial10Italic).Height; } // Draw Total: text = "Total: "; e.Graphics.DrawString(text, drawFontArial14Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); text = "R$ " + total.ToString().Replace(".", ","); e.Graphics.DrawString(text, drawFontArial14Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatRight); y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height; // Draw separation line x = 5; text = new String('=', 40); e.Graphics.DrawString(text, drawFontArial10Bold, drawBrush, new RectangleF(x, y, width + 10, height), drawFormatLeft); y += e.Graphics.MeasureString(text, drawFontArial10Bold).Height; // Draw extra footnote, if any if (xtra > 0) { text = "*Item fora do cardápio"; e.Graphics.DrawString(text, drawFontArial10Italic, drawBrush, new RectangleF(x, y, width, height), drawFormatLeft); y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height; } // Draw space below for cutting // ... and so on }
private BillingDocument showOrder(Order id) { var orderDB = new DBOrder(); List<OrderLine> list = orderDB.getOrder(id.id); List<ShoppingCartItem> cartItems = new List<ShoppingCartItem>(); var cartSum = 0; foreach(var item in list){ cartItems.Add(new ShoppingCartItem(item.product, item.quantity)); cartSum += item.product.price * item.quantity; }; var cart = new ShoppingCart(id.customerid) { shoppingCartItems = cartItems, sum = cartSum }; var billingDoc = new BillingDocument(){ order = id, customer = (Customer) Session["LoggedInUser"], shoppingcart = cart, sum = cart.sum, exmva = cart.sum * 0.8, mva = cart.sum * 0.2 }; return billingDoc; }
public static void prepareSync(bool isKiosk = false) { var dateNow = string.Format("{0:yyyy-MM-ddTH:mm:sszzz}", DateTime.Now); var activeLocalContacts = DBLocalDataStore.GetInstance().GetLocalContacts().Where(c => c.activeContact).ToList(); if (activeLocalContacts.Count == 0 && !isKiosk) { throw new InvalidOperationException("Please select at least one contact."); } var allactivefiles = DBLocalDataStore.GetInstance().GetAllLocalFiles().Where(s => s.activeFile).ToList(); var appInfo = DBLocalDataStore.GetInstance().GetAppInfo(); var user = DBLocalDataStore.GetInstance().GetLocalUserInfo(); var contactsToSend = DBLocalDataStore.GetInstance().GetContactsToServer(); var invalidContactsToSend = contactsToSend.Where(c => string.IsNullOrWhiteSpace(c.uid)); foreach (var invalidItem in invalidContactsToSend) { DBLocalDataStore.GetInstance().RemoveContactToServer(invalidItem); } contactsToSend.RemoveAll(c => string.IsNullOrWhiteSpace(c.uid)); var answersToSend = DBLocalDataStore.GetInstance().getAnswers(); var formDefinition = DBLocalDataStore.GetInstance().GetLocalFormDefinitions().Find(s => s.uuid == DBLocalDataStore.GetInstance().GetSelectedQuestionPosition()); var questions = DBLocalDataStore.GetInstance().GetLocalQuestions(formDefinition.uuid); List <DBOrder> orders = new List <DBOrder>(); List <DBOrderLine> orderLines = new List <DBOrderLine>(); allactivefiles.ForEach((f) => { DBOrderLine orderLine = new DBOrderLine(); orderLine.itemDescription = f.name; orderLine.item = f.uuid; orderLines.Add(orderLine); }); activeLocalContacts.ForEach((lc) => { if (string.IsNullOrWhiteSpace(lc.uid)) { return; } var serverContact = contactsToSend.Find(sc => sc.uid.Equals(lc.uid)); if (serverContact == null) { DBContactToServer newServerContact = new DBContactToServer(true); newServerContact.uid = lc.uid; DBLocalDataStore.GetInstance().AddContactToServer(newServerContact); contactsToSend.Add(newServerContact); } DBOrder order = new DBOrder(); order.contactUid = lc.uid; order.created = DateTime.Now.ToString("yyyy-MM-ddTH:mm:sszzz"); order.creator = user.username; order.orderLine = orderLines; orders.Add(order); }); SyncContext scr = new SyncContext(); scr.context = new RequestData(); scr.contacts = new List <CustomerType>(); scr.forms = new List <AnsweredForm>(); scr.orders = orders; contactsToSend.ForEach((c) => { //scr.contacts.Add(new CustomerType(c)); if (!string.IsNullOrWhiteSpace(c.uid)) { scr.contacts.Add(new CustomerType(c)); } }); bool isAnyQuestionAnswered = answersToSend.Count(s => OfflineLogic.isAnswerValid(s.answer)) > 0; string profileName = DBLocalDataStore.GetInstance().GetSelectProfile().shortName; foreach (var contact in activeLocalContacts) { bool isAnswersValid = true; if (isAnyQuestionAnswered) { var form = new AnsweredForm(); List <Answer> tmpAnswers = new List <Answer>(); form.contactUid = contact.uid; form.startdate = dateNow; form.enddate = dateNow; form.name = formDefinition.objectName; form.user = new DeviceUser { username = user.username, profile = profileName }; form.answers = new Answer[] { }; for (int index = 0; (index < answersToSend.Count) && isAnyQuestionAnswered; index++) { if (OfflineLogic.isAnswerValid(answersToSend[index].answer)) { Answer answer = new Answer(); answer.answer = answersToSend[index].answer; answer.name = questions[index].name; answer.type = questions[index].type; tmpAnswers.Add(answer); } else { if (OfflineLogic.isQuestionRequired(questions[index])) { isAnswersValid = false; } } } if (isAnswersValid) { form.answers = tmpAnswers.ToArray(); scr.forms.Add(form); } else { if (!isKiosk) { throw new InvalidOperationException("Not all mandatory questions are completed"); } } } } var Counts = DBLocalDataStore.GetInstance().GetCountHomeScreen(); for (int i = 0; i < scr.contacts.Count; i++) { activeLocalContacts[i].useInRequest = true; DBLocalDataStore.GetInstance().UpdateLocalContact(activeLocalContacts[i]); } if (scr.orders[0].orderLine.Count != 0) { Counts.countShare += scr.orders.Count; } Counts.countQuestion += scr.forms.Count; Counts.countContacts = DBLocalDataStore.GetInstance().GetLocalContacts().Where(c => c.useInRequest).ToList().Count; DBLocalDataStore.GetInstance().SetCountHomeScreen(Counts); JsonSerializerSettings serializationSettings = new JsonSerializerSettings(); serializationSettings.DefaultValueHandling = DefaultValueHandling.Ignore; string json = JsonConvert.SerializeObject(scr, Formatting.Indented, serializationSettings); DBSyncRequest syncRequest = new DBSyncRequest(); syncRequest.serializedSyncContext = json; Console.Error.WriteLine("Saving request: {0}", json); DBLocalDataStore.GetInstance().addSyncRequest(syncRequest); // DBLocalDataStore.GetInstance().SetCountHomeScreen(new DBHomeScreenCounts() { countContacts = ActivityHomescreen.counts[0], countShare = ActivityHomescreen.counts[1], countQuestion = ActivityHomescreen.counts[2] }); if (!isKiosk) { OfflineLogic.ClearDataSelected(); } }
public ActionResult checkout(Order order) { RedirectToAction("viewShoppingCart"); if (order.id != 0) { return View(showOrder(order)); } ViewBag.Empty = false; ShoppingCart cart = getCart(); if (cart == null) { ViewBag.Empty = true; return View(); } var orderDB = new DBOrder(); var OrderId = orderDB.checkout(cart); var returnCustomer= (Customer) Session["LoggedInUser"]; returnCustomer.shoppingcart = new ShoppingCart(returnCustomer.id); Session["LoggedInUser"] = returnCustomer; return View(new BillingDocument() { customer = returnCustomer, shoppingcart = cart, order = new Order() { id = OrderId, customerid = returnCustomer.id, orderdate = DateTime.Now }, sum = cart.sum, exmva = cart.sum * 0.8, mva = cart.sum * 0.2 }); }