private async void Sure_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(SaleNumberBox.Text) || string.IsNullOrEmpty(BookIDBox.Text)) { return; } Models.Stock stock = StockUtil.QueryStock(BookIDBox.Text); if (stock != null) { int n = int.Parse(SaleNumberBox.Text); SaleNumberBox.Text = ""; if (n > stock.Number) { await new MessageDialog("这种书没有多么多了!").ShowAsync(); return; } // 库存记录 StockViewModel.GetInstance().UpdateStock(stock.Book.BId, 0 - n); // 销售记录 Models.Sale sale = new Models.Sale { Book = stock.Book, Number = n, Time = DateTimeOffset.Now, TotalPrice = n * stock.SalePrice }; SalesUtil.AddSale(sale); await new MessageDialog("销售成功!").ShowAsync(); } else { await new MessageDialog("没有这种书,请重新输入书籍编号!").ShowAsync(); } BookIDBox.Text = ""; }
public IActionResult Add(SaleRequest model) { var response = new Response(); try { using var db = new salesSystemContext(); using var transaction = db.Database.BeginTransaction(); try { var sale = new Models.Sale { Total = model.Concepts.Sum(d => d.Amount * d.PriceUnit), CreatedAt = DateTime.Now, FkClientId = model.IdClient }; db.Sales.Add(sale); db.SaveChanges(); foreach (var concept in model.Concepts.Select(rowConcept => new Concept { FkProductId = rowConcept.IdProduct, PriceUnit = rowConcept.PriceUnit, Amount = rowConcept.Amount, Total = rowConcept.Total, FkSaleId = sale.Id })) { db.Concepts.Add(concept); db.SaveChanges(); } response.Success = true; transaction.Commit(); } catch (Exception e) { Console.WriteLine(e); transaction.Rollback(); } } catch (Exception e) { Console.WriteLine(e); response.Message = e.Message; return(BadRequest(response)); } return(Ok(response)); }
private void AddSaleReportRow(float fontSize, Font.FontFamily fontFamily, IList <PdfPCell> cells, Models.Sale sale, string measure, string productName, string location) { cells.Add(new PdfPCell(new Phrase(productName, new Font(fontFamily, fontSize, Font.BOLD))) { PaddingBottom = 10, PaddingTop = 10, HorizontalAlignment = 1 }); cells.Add(new PdfPCell(new Phrase(string.Format("{0} {1}", sale.Quantity, measure), new Font(fontFamily, fontSize, Font.BOLD))) { PaddingBottom = 10, PaddingTop = 10, HorizontalAlignment = 1 }); cells.Add(new PdfPCell(new Phrase(sale.UnitPrice.ToString(), new Font(fontFamily, fontSize, Font.BOLD))) { PaddingBottom = 10, PaddingTop = 10, HorizontalAlignment = 1 }); cells.Add(new PdfPCell(new Phrase(location, new Font(fontFamily, fontSize, Font.BOLD))) { PaddingBottom = 10, PaddingTop = 10, HorizontalAlignment = 1 }); cells.Add(new PdfPCell(new Phrase(sale.Sum.ToString(), new Font(fontFamily, fontSize, Font.BOLD))) { PaddingBottom = 10, PaddingTop = 10, HorizontalAlignment = 1 }); }
public string Buy(int ResellerId, string CustomerId, Int64 InvoiceNo, double DiscountMargin) { string OffersName = string.Empty; using (var db = new ViewModel.Context.ConnectionStringsContext()) using (var dbContextTransaction = db.Database.BeginTransaction()) { try { ViewModel.AddToCart.AddToCart cart = new ViewModel.AddToCart.AddToCart(); List <Models.CartMicrosoftPriceRepo> CartMicrosoftPriceRepo = cart.Get(0, CustomerId, true); //Save the information on sale table Models.Sale sale = new Models.Sale { CustomerId = CustomerId, InvoiceNo = InvoiceNo, ResellerId = ResellerId, SaleDate = DateTime.Now, DiscountMargin = DiscountMargin }; db.Sale.Add(sale); db.SaveChanges(); //Save the items in db foreach (var item in CartMicrosoftPriceRepo) { ViewModel.Subscription.Subscriptions subscriptions = new Subscription.Subscriptions(ApplicationDomain.Instance); OffersName += item.Name + ", "; Microsoft.Store.PartnerCenter.Models.Orders.Order order = subscriptions.PlaceOrder(CustomerId, item.MicrosoftId, item.License, Models.PurchaseUnit.Months, item.Name); Models.SaleItems saleItems = new Models.SaleItems { License = item.License, OfferId = item.MicrosoftId, OriginalPrice = (double)System.Math.Round(item.ERPrice, 2), SaleId = sale.Id, DiscountPrice = (double)System.Math.Round(item.ERPrice - (item.ERPrice * DiscountMargin) / 100, 2), PurchaseUnitNumber = 0, PurchaseUnit = 0, OrderId = order.Id, }; db.SaleItems.Add(saleItems); db.SaveChanges(); } // If items are sale then remove that items from cart db.Cart.Where(m => m.AgentId == ResellerId && m.Status == true).ToList().ForEach(c => c.Status = false); db.SaveChanges(); dbContextTransaction.Commit(); //Send email to customer SendEmailOffer(OffersName, CustomerId); return("Successfully Items has been purchased"); } catch { dbContextTransaction.Rollback(); return("Unknown error occur, Please try again."); } } }
private const string ApiBaseUrl = null; // Set to `null` to use the default. public static void Main() { try { Console.Title = "EstateSales.NET Public Sales API Demo"; string apiKey = ConsoleHelpers.Prompt <string>("Enter your API Key"); int orgId = ConsoleHelpers.Prompt <int>("Enter your Org ID"); // First create a new client to interact with the API. Client client = string.IsNullOrEmpty(ApiBaseUrl) ? new Client(apiKey) : new Client(apiKey, ApiBaseUrl); // You can do things like get your current list of sales. Console.WriteLine(); Console.WriteLine("Retrieving your active sales..."); IReadOnlyCollection <Models.Sale> editableSales = client.GetEditableSales(orgId); if (editableSales.Any()) { Console.WriteLine($"You have {editableSales.Count} editable sale(s)!"); foreach (Models.Sale editableSale in editableSales) { Console.WriteLine($"{editableSale.Name} ({(editableSale.IsPublished ? "Published" : "Not Published")}) ({ApiBaseUrl}{editableSale.Url})"); Console.WriteLine($"Date Count: {client.GetSaleDates(editableSale.Id).Count} / Picture Count: {client.GetSalePictures(editableSale.Id).Count}"); Console.WriteLine(); } } else { Console.WriteLine("You have no editable sales. :( That's okay though, we're about to learn how to add one!"); } Console.WriteLine(); Console.WriteLine("Next, we will add a new sale..."); Console.WriteLine(); // You can create a sale. Models.Sale sale = GetSampleSale(orgId); Console.WriteLine(); Console.WriteLine("Saving your sale..."); sale = client.CreateSale(sale); Console.WriteLine(); Console.WriteLine("Setting your new sale to run for the next three days..."); // You can use that savedSale and create some dates on your sale. // We are just setting up the objects to send... DateTime tomorrowAt9am = DateTime.Now.Date.AddDays(1).AddHours(9).ToUniversalTime(); DateTime tomorrowAt4pm = DateTime.Now.Date.AddDays(1).AddHours(16).ToUniversalTime(); Models.SaleDate date1 = GetSampleSaleDate(sale.Id, tomorrowAt9am, tomorrowAt4pm); Models.SaleDate date2 = GetSampleSaleDate(sale.Id, tomorrowAt9am.AddDays(1), tomorrowAt4pm.AddDays(1)); Models.SaleDate date3 = GetSampleSaleDate(sale.Id, tomorrowAt9am.AddDays(2), tomorrowAt4pm.AddDays(2)); // Now we are sending those to the API to be saved. date1 = client.CreateSaleDate(date1); date2 = client.CreateSaleDate(date2); date3 = client.CreateSaleDate(date3); Models.SalePicture pic1 = null; Console.WriteLine(); string picturePath = ConsoleHelpers.Prompt <string>("Enter a path to a picture (optional)"); if (string.IsNullOrEmpty(picturePath) == false) { if (File.Exists(picturePath)) { Console.WriteLine(); Console.WriteLine("Uploading your sale picture..."); // Get a picture ready to go. pic1 = GetSampleSalePicture(sale.Id, "testing", picturePath); // Send it to the API to be saved. pic1 = client.CreateSalePicture(pic1); } else { Console.WriteLine("File not found, skipping picture upload."); } } // You can publish your sale. ////client.PublishSale(sale.Id, false); Process.Start($"{ApiBaseUrl ?? "https://www.estatesales.net"}{sale.Url}"); Console.WriteLine(); Console.WriteLine($"Okay, your sale created and populated with dates and a picture!"); Console.WriteLine($"You can view it at https://www.estatesales.net{sale.Url}."); ConsoleHelpers.Pause(); // You can unpublish your sale. ////client.UnpublishSale(sale.Id); // You can update things on your sale if you need to. ////sale.Directions = "These are my new directions."; ////sale.Description = "This is my updated description."; ////client.UpdateSale(sale); Console.WriteLine(); Console.WriteLine("Next, we will delete the sale we just created..."); // You can delete any pictures you'd like (as long as you saved their id when initially saving them). if (pic1 != null) { client.DeletePicture(pic1.Id); } // You can delete any dates you'd like IEnumerable <Models.SaleDate> dates = client.GetSaleDates(sale.Id); foreach (Models.SaleDate saleDate in dates) { client.DeleteSaleDate(saleDate.Id); } // If you stored the date ids previously, you don't have to look them up first ////client.DeleteSaleDate(date1.Id); ////client.DeleteSaleDate(date2.Id); ////client.DeleteSaleDate(date3.Id); // You can delete your sale if you need to. // You do not need to delete the sale dates and sale pictures first. You can just delete the sale. client.DeleteSale(sale.Id); Console.WriteLine(); Console.WriteLine("Okay, we're done now. Enjoy using the EstateSales.NET Sales API!"); } catch (Exception exception) { Console.WriteLine(); Console.WriteLine("An error occurred:"); Console.WriteLine(exception.Message); Console.WriteLine(); } ConsoleHelpers.Pause(true); }
public static Sale From(Models.Sale source) { return(new Sale().PopulateWith(source)); }