public FileStreamResult CreateLieferschein(LieferscheinViewModel model) { LieferscheinData data = Mapper.Map <LieferscheinData>(model); if (model.BestehenderKunde != null) { SetKundenInfo(data, model.BestehenderKunde); } SetPrices(data); SetLieferscheinNr(data); data = CalculateService.CalulateLieferscheinTotals(data); DocX doc = LieferscheinService.Create(data); MemoryStream ms = new MemoryStream(); doc.SaveAs(ms); ms.Position = 0; string FILENAME = $"Lieferschein_{data.LieferNr.ToString()}.docx"; var file = new FileStreamResult(ms, CONTENTTYPEWORD) { FileDownloadName = string.Format(FILENAME) }; return(file); }
private static DocX PopulateVorlageWithRechnungData(LieferscheinData data) { Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Bearfoods.LieferscheinPath); DocX document = DocX.Load(stream).Copy(); document.ReplaceText(nameof(data.KundenName), data.KundenName ?? string.Empty); document.ReplaceText(nameof(data.AdressZeile1), data.AdressZeile1 ?? string.Empty); document.ReplaceText(nameof(data.AdressZeile2), data.AdressZeile2 ?? string.Empty); document.ReplaceText(nameof(data.LieferNr), data.LieferNr ?? string.Empty); document.ReplaceText(nameof(data.KundeNr), data.KundeNr ?? string.Empty); document.ReplaceText(nameof(data.LieferDatum), data.LieferDatum.ToShortDateString()); document.ReplaceText(nameof(data.MengeBBQSmall), data.MengeBBQSmall == 0 ? string.Empty : data.MengeBBQSmall.ToString()); document.ReplaceText(nameof(data.MengeBBQ), data.MengeBBQ == 0 ? string.Empty : data.MengeBBQ.ToString()); document.ReplaceText(nameof(data.MengePizza), data.MengePizza == 0 ? string.Empty : data.MengePizza.ToString()); document.ReplaceText(nameof(data.MengeJusSmall), data.MengeJusSmall == 0 ? string.Empty : data.MengeJusSmall.ToString()); document.ReplaceText(nameof(data.MengeJus), data.MengeJus == 0 ? string.Empty : data.MengeJus.ToString()); document.ReplaceText(nameof(data.EinzelpreisBBQSmall), data.EinzelpreisBBQSmall == 0 ? string.Empty : data.EinzelpreisBBQSmall.ToString()); document.ReplaceText(nameof(data.EinzelpreisBBQ), data.EinzelpreisBBQ == 0 ? string.Empty : data.EinzelpreisBBQ.ToString()); document.ReplaceText(nameof(data.EinzelpreisPizza), data.EinzelpreisPizza == 0 ? string.Empty : data.EinzelpreisPizza.ToString()); document.ReplaceText(nameof(data.EinzelpreisJusSmall), data.EinzelpreisJusSmall == 0 ? string.Empty : data.EinzelpreisJusSmall.ToString()); document.ReplaceText(nameof(data.EinzelpreisJus), data.EinzelpreisJus == 0 ? string.Empty : data.EinzelpreisJus.ToString()); document.ReplaceText(nameof(data.TotalBBQSmall), data.TotalBBQSmall == 0 ? string.Empty : data.TotalBBQSmall.ToString()); document.ReplaceText(nameof(data.TotalBBQ), data.TotalBBQ == 0 ? string.Empty : data.TotalBBQ.ToString()); document.ReplaceText(nameof(data.TotalPizza), data.TotalPizza == 0 ? string.Empty : data.TotalPizza.ToString()); document.ReplaceText(nameof(data.TotalJusSmall), data.TotalJusSmall == 0 ? string.Empty : data.TotalJusSmall.ToString()); document.ReplaceText(nameof(data.TotalJus), data.TotalJus == 0 ? string.Empty : data.TotalJus.ToString()); document.ReplaceText(nameof(data.Total), data.Total == 0 ? string.Empty : data.Total.ToString()); return(document); }
public void TestCreate_One_Product_Jus() { // Arrange LieferscheinData data = CreateLieferscheinData(); data.LieferDatum = DateTime.Today; data.LieferNr = "0079"; data.EinzelpreisJus = 12.00m; data.TotalJus = 24.00m; data.MengeJus = 2; data.Total = 24.00m; data.MengeBBQ = 0; data.MengePizza = 0; // Act DocX document = LieferscheinService.Create(data); document.SaveAs(FILE_NAME); // Assert Assert.IsNotNull(document); Assert.IsTrue(File.Exists(FILE_NAME)); Assert.IsFalse(document.Tables.Any(x => x.Rows.Any(y => y.Cells.Any(p => p.Paragraphs.Any(t => t.Text.Contains(Bearfoods.Pizza)))))); Assert.IsFalse(document.Tables.Any(x => x.Rows.Any(y => y.Cells.Any(p => p.Paragraphs.Any(t => t.Text.Contains(Bearfoods.BBQ)))))); Assert.IsTrue(document.Tables.Any(x => x.Rows.Any(y => y.Cells.Any(p => p.Paragraphs.Any(t => t.Text.Contains(Bearfoods.Jus)))))); }
private void SetKundenInfo(LieferscheinData data, string bestehenderKunde) { Kunde kunde = KundenConfig.Value.Kunden.Find(x => x.Name == bestehenderKunde); data.KundenName = kunde.Name; data.AdressZeile1 = kunde.Adresse1; data.AdressZeile2 = kunde.Adresse2; data.KundeNr = kunde.KundenNr; }
public void TestCalculatePrices_Lieferschein() { // Arrange LieferscheinData data = CreateLieferscheinData(); // Act data = CalculateService.CalulateLieferscheinTotals(data); // Assert Assert.AreEqual(76m, data.Total); Assert.AreEqual(16m, data.TotalBBQ); Assert.AreEqual(24m, data.TotalPizza); Assert.AreEqual(36m, data.TotalJus); }
public void TestCreate_Full() { // Arrange LieferscheinData data = CreateLieferscheinData(); // Act DocX document = LieferscheinService.Create(data); document.SaveAs(FILE_NAME); // Assert Assert.IsNotNull(document); Assert.IsTrue(File.Exists(FILE_NAME)); }
public LieferscheinData CalulateLieferscheinTotals(LieferscheinData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } data.TotalBBQ = data.EinzelpreisBBQ * data.MengeBBQ; data.TotalPizza = data.EinzelpreisPizza * data.MengePizza; data.TotalJus = data.EinzelpreisJus * data.MengeJus; data.Total = data.TotalBBQ + data.TotalPizza + data.TotalJus + data.TotalBBQSmall + data.TotalJusSmall; return(data); }
private void SetPrices(LieferscheinData data) { data.EinzelpreisBBQ = PricesConfig.Value.BBQPrice; data.TotalBBQ = data.EinzelpreisBBQ * data.MengeBBQ; data.EinzelpreisBBQSmall = PricesConfig.Value.BBQPriceSmall; data.TotalBBQSmall = data.EinzelpreisBBQSmall * data.MengeBBQSmall; data.EinzelpreisPizza = PricesConfig.Value.PizzaPrice; data.TotalPizza = data.EinzelpreisPizza * data.MengePizza; data.EinzelpreisJus = PricesConfig.Value.JusPrice; data.TotalJus = data.EinzelpreisJus * data.MengeJus; data.EinzelpreisJusSmall = PricesConfig.Value.JusPriceSmall; data.TotalJusSmall = data.EinzelpreisJusSmall * data.MengeJusSmall; }
private void SetLieferscheinNr(LieferscheinData data) { if (System.IO.File.Exists("counters.json")) { Counters counters; using (StreamReader reader = new StreamReader("counters.json")) { string jsonCounters = reader.ReadToEnd(); counters = JsonConvert.DeserializeObject <Counters>(jsonCounters); } data.LieferNr = counters.LieferscheinNr.ToString(); counters.LieferscheinNr += 1; string jsonToBeWritten = JsonConvert.SerializeObject(counters); System.IO.File.WriteAllText("counters.json", jsonToBeWritten); } }
public DocX Create(LieferscheinData data) { DocX document = PopulateVorlageWithRechnungData(data); bool hasBBQ = data.MengeBBQ > 0; bool hasPizza = data.MengePizza > 0; bool hasJus = data.MengeJus > 0; bool hasJusSmall = data.MengeJusSmall > 0; bool hasBBQSmall = data.MengeBBQSmall > 0; if (!hasBBQ) { RemoveProductRow(document, Bearfoods.BBQ); } if (!hasPizza) { RemoveProductRow(document, Bearfoods.Pizza); } if (!hasJus) { RemoveProductRow(document, Bearfoods.Jus); } if (!hasJusSmall) { RemoveProductRow(document, Bearfoods.JusSmall); } if (!hasBBQSmall) { RemoveProductRow(document, Bearfoods.BBQSmall); } return(document); }