public void AddQuestion() { string[] answersToAdd = new string[4] { answerField0.text, answerField1.text, answerField2.text, answerField3.text }; answersToAdd = OrderIn.Shuffle <string>(answersToAdd); int i = 0; foreach (string answer in answersToAdd) { if (answer == answerField0.text) { break; } else { i++; } } qM.AddQuestion(questionField.text, answersToAdd, i); }
public IActionResult Create([FromBody] OrderIn orderIn) { try { var orderOut = orderService.Create(orderIn, User.GetId()); return(Json(orderOut)); } catch (ArgumentException ex) { Response.StatusCode = 403; var msg = new JsonMessage(ex.Message.Length > 0 ? ex.Message : "Что-то пошло не так", ""); return(Json(msg)); } }
public OrderOut Create(OrderIn orderIn, string buyerId) { var order = MapHelper.Map <OrderIn, Order>(orderIn); try { var buyer = ffContext.Users.Single(u => u.Id == buyerId); order.Buyer = buyer; } catch (Exception ex) { throw new ArgumentException("Невалидный пользователь, обновите токен"); } var outlet = ffContext.Outlets.Single(o => o.Id == orderIn.OutletId); order.Outlet = outlet; order.Index = OrderHelper.GenerateIndex(); order.OrderTime = DateTime.Now; order.Status = "Создан"; ffContext.Orders.Add(order); ffContext.SaveChanges(); foreach (var productInOrder in orderIn.Products) { var productOrder = new ProductOrder { Amount = productInOrder["amount"].ToObject <int>(), OrderId = order.Id, ProductId = productInOrder["id"].ToObject <string>() }; ffContext.ProductsOrder.Add(productOrder); } ffContext.SaveChanges(); return(Get(order.Id)); }
public void ShuffleAll() { //Copy the list to shuffle List <Question> copy = GetCurrentTest().questions.ToList(); // List <Question> list = GetCurrentTest().questions; // //for every item in the list, replace it with a random item in the copied list and then remove it for (int item = 0; item < list.Count; item++) { int randomItem = (int)Random.Range(0, copy.Count); list[item] = copy[randomItem]; string rightAnswer = list[item].answers[list[item].rightAnswer]; list[item].answers = OrderIn.Shuffle(list[item].answers); int i = 0; foreach (string answer in list[item].answers) { if (answer == rightAnswer) { list[item].rightAnswer = i; break; } else { i++; } } copy.RemoveAt(randomItem); } Debug.Log(list.Count); }
public static void LoadTestData(AppRepository <KfsContext> appRespository) { //als deze gebruiker bestaat, returnen, data moet niet opnieuw opgeslagen worden EmployeeRepository.EmployeeLoggedInDTO tmpTest = appRespository.Employee.LogIn("Tom_0123", "Tom_0123"); if (tmpTest != null) { return; } #region =============================== MIN APPLICATIE VEREISTE ==================================== #region ------------------------------------------- Add Departments------------------------------ EmpDepartment newDep_admin = new EmpDepartment() { DefaultPermissions = 0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111, DescriptionNL = "Administrator", DescriptionEN = "Administrator" }; appRespository.EmpDepartment.Add(newDep_admin); EmpDepartment newDep_Sales = new EmpDepartment() { DefaultPermissions = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1111_1111_1111_1111_1111, DescriptionEN = "Sales", DescriptionNL = "Verkoop" }; appRespository.EmpDepartment.Add(newDep_Sales); EmpDepartment newDep_Warehouse = new EmpDepartment() { DefaultPermissions = 0b0000_0000_0000_0000_1111_1111_1111_1111_1111_1111_0000_0000_0000_0000_0000_0000, DescriptionEN = "Ware House", DescriptionNL = "Magazijn" }; appRespository.EmpDepartment.Add(newDep_Warehouse); #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Contract types--------------------------- EmpContractType newContrType_onbDuur = new EmpContractType() { DescriptionEN = "Indefinitely", DescriptionNL = "Onbepaalde duur" }; appRespository.EmpContractType.Add(newContrType_onbDuur); EmpContractType newContrType_jobstudent = new EmpContractType() { DescriptionEN = "Student job", DescriptionNL = "Jobstudent" }; appRespository.EmpContractType.Add(newContrType_jobstudent); EmpContractType newContrType_interim = new EmpContractType() { DescriptionEN = "Interim", DescriptionNL = "Interim" }; appRespository.EmpContractType.Add(newContrType_interim); #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add EmpContractStatuutType------------------- EmpContractStatuutType empContrStatuutType_arbeider = new EmpContractStatuutType { DescriptionEN = "Worker", DescriptionNL = "Arbeider" }; appRespository.EmpContractStatuutType.Add(empContrStatuutType_arbeider); EmpContractStatuutType empContrStatuutType_bediende = new EmpContractStatuutType { DescriptionEN = "Servant", DescriptionNL = "Bediende" }; appRespository.EmpContractStatuutType.Add(empContrStatuutType_bediende); EmpContractStatuutType empContrStatuutType_Ambtenaar = new EmpContractStatuutType { DescriptionEN = "Civil servant", DescriptionNL = "Ambtenaar" }; appRespository.EmpContractStatuutType.Add(empContrStatuutType_Ambtenaar); #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add ProductType------------------------------ ProductType productType_Dranken = new ProductType() { DescriptionNL = "Dranken", DescriptionEN = "Drinks" }; appRespository.ProductType.Add(productType_Dranken); ProductType productType_Speelgoed = new ProductType() { DescriptionNL = "Speelgoed", DescriptionEN = "Toys" }; appRespository.ProductType.Add(productType_Speelgoed); ProductType productType_Voedingswaren = new ProductType() { DescriptionNL = "Voedingswaren", DescriptionEN = "Foodstuffs" }; appRespository.ProductType.Add(productType_Voedingswaren); ProductType productType_AutoOnderdelen = new ProductType() { DescriptionNL = "Auto onderdelen", DescriptionEN = "Car parts" }; appRespository.ProductType.Add(productType_AutoOnderdelen); #endregion -------------------------------------------------------------------------------------- #region employee_TomDilen amdin met alle rechten Employee employee_TomDilen = new Employee() { //-------------------personMin--------- FirstName = "Tom", //NameAddition = "niet vereist", LastName = "Dilen", Email = "*****@*****.**", MobileNumber = "0123 11 22 33", //PhoneNumber = "niet vereist", //navprops //-------------------Person------------ DateOfBirth = new DateTime(1981, 04, 22), IsMale = true, //nav props EmpAddress = new EmpAddress() { Street = "Duivenstraat", HouseNumber = 55, //HouseNumberAddition = "nvt", Zipcode = "2300", City = "Turnhout", Country = "Belgium" }, //-------------------Employee---------- PassPortID = "0122222111", IBAN = "12220132145545", JobInfo = "waarken lak een biest", ExtraInfo = "zag er ne toffe gast uit bij de sollicitatie", //navProps //id voor departement is genoeg :-) Id_EmpDepartment = 1, //1=Administrator, 2=Verkoop, 3=Magazijn EmpContract = new EmpContract() { MonthSalary = 2222.22f, DateOfStart = new DateTime(2020, 12, 2), Id_EmpContractStatuutType = 1, // 1=Arbeider, 2=Bediende, 3=Ambtenaar Id_EmpContractType = 1 // 1=Onbepaalde duur, 2=Jobstudent, 3=Interim }, EmpAppAccount = new EmpAppAccount { //AppPermissions = 0b0100_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1111_1111_1111_1111_1111, AppPermissions = 0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111, Password = "******", UserName = "******", IsPaswordResseted = true, LastResetted = DateTime.Now, IsBlocked = false, InlogAttempts = 0, } }; appRespository.Employee.Add(employee_TomDilen); //inloggen EmployeeRepository.EmployeeLoggedInDTO IngelogdGebruiker = appRespository.Employee.LogIn("Tom_0123", "Tom_0123"); if (IngelogdGebruiker == null) { System.Windows.Forms.MessageBox.Show("null"); } else { System.Windows.Forms.MessageBox.Show("joepi, ingelogd"); } #endregion #endregion ================================================================================================== #region ------------------------------------------- Add Employees ------------------------------ #region employee_MaggieDeBlock Employee employee_MaggieDeBlock = new Employee() { //-------------------personMin--------- FirstName = "Maggie", NameAddition = "De", LastName = "Block", Email = "*****@*****.**", MobileNumber = "0123 45 67 89", PhoneNumber = "23 23 23 23 23", //navprops //-------------------Person------------ DateOfBirth = new DateTime(1981, 04, 22), IsMale = true, //nav props EmpAddress = new EmpAddress() { Street = "vetstraat", HouseNumber = 55, //HouseNumberAddition = "nvt", Zipcode = "1000", City = "Brussel", Country = "Belgium" }, //-------------------Employee---------- PassPortID = "01222244444", IBAN = "12220132148888", JobInfo = "mondmaskers verbranden", ExtraInfo = "toffe griet yoh", //navProps //id voor departement is genoeg :-) Id_EmpDepartment = 3, //1=Administrator, 2=Verkoop, 3=Magazijn EmpContract = new EmpContract() { MonthSalary = 1400.22f, DateOfStart = new DateTime(1950, 11, 22), Id_EmpContractStatuutType = 2, // 1=Arbeider, 2=Bediende, 3=Ambtenaar Id_EmpContractType = 2 // 1=Onbepaalde duur, 2=Jobstudent, 3=Interim }, //EmpAppAccount = new EmpAppAccount //{ // AppPermissions = Int64.MaxValue, // Password = "******", // UserName = "******", // IsPaswordResseted = true, // LastResetted = DateTime.Now, // IsBlocked = false, // InlogAttempts = 0, //} }; appRespository.Employee.Add(employee_MaggieDeBlock); #endregion #region employee_AlexanderDeCroo Employee employee_AlexanderDeCroo = new Employee() { //-------------------personMin--------- FirstName = "Alexander", NameAddition = "De", LastName = "Kraai", Email = "*****@*****.**", MobileNumber = "0123 45 67 40", PhoneNumber = "23 23 23 23 98", //navprops //-------------------Person------------ DateOfBirth = new DateTime(1982, 04, 1), IsMale = true, //nav props EmpAddress = new EmpAddress() { Street = "wetstraat", HouseNumber = 55, //HouseNumberAddition = "nvt", Zipcode = "1040", City = "Vettigem", Country = "Duitsland" }, //-------------------Employee---------- PassPortID = "5555555555", IBAN = "121212121212", JobInfo = "Graaien in de vetpot", ExtraInfo = "nen echte fille de papa", //navProps //id voor departement is genoeg :-) Id_EmpDepartment = 2, //1=Administrator, 2=Verkoop, 3=Magazijn EmpContract = new EmpContract() { MonthSalary = 1200.22f, DateOfStart = new DateTime(1970, 11, 22), Id_EmpContractStatuutType = 3, // 1=Arbeider, 2=Bediende, 3=Ambtenaar Id_EmpContractType = 3 // 1=Onbepaalde duur, 2=Jobstudent, 3=Interim }, EmpAppAccount = new EmpAppAccount { AppPermissions = Int64.MaxValue, Password = "******", UserName = "******", IsPaswordResseted = true, LastResetted = DateTime.Now, IsBlocked = false, InlogAttempts = 0, } }; appRespository.Employee.Add(employee_AlexanderDeCroo); #endregion #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Suppliers-------------------------------- Supplier supPConderdelen = new Supplier() { CmpManagers = new List <CmpManager>() { new CmpManager() { FirstName = "TomsupPConderdelen", //NameAddition = "van", LastName = "ManagersupPConderdelen", Email = "*****@*****.**", MobileNumber = "0114", PhoneNumber = "222222244522" } }, CompanyNumber = "551555555", Name = "supPConderdelen Turnhout", Website = "supPConderdelenTurnhout.be", BtwNumber = "BE 4555555", Email = "*****@*****.**", ExtraInfo = "dit is extrainfo over supPConderdelen turnhout", CmpIBANs = new List <CmpIBAN>() { new CmpIBAN { Number = "222-22222-22-222", IsDefault = true } }, CmpSites = new List <CmpSite>() { new CmpSite() { IsDefault = true, CmpSiteAddress = new CmpSiteAddress() { Street = "gasthuissstraat", HouseNumber = 55, HouseNumberAddition = "22", Country = "Belgie", Zipcode = "2000", City = "Antwerpen" }, Fax = "222222222", PhoneNumber = "012345678", PhoneNumber_2 = "555220", MobileNumber = "014556699", Email = "*****@*****.**", ExtraInfo = "extra info over hoofdsite van supPConderdelen Turnhout", CmpSiteContactPersons = new List <CmpSiteContactPerson>() { new CmpSiteContactPerson() { FirstName = "TomsupPConderdelenContact", //NameAddition = "van", LastName = "DilenContact", Email = "*****@*****.**", MobileNumber = "0111111111121", PhoneNumber = "2222222222", IsDefault = true, ExtraInfo = "geen extra info over dez contactpersoon van supPConderdelen" } }, }, }, }; appRespository.Supplier.Add(supPConderdelen); Supplier supCocaCola = new Supplier() { CmpManagers = new List <CmpManager>() { new CmpManager() { FirstName = "TomCocaCola", //NameAddition = "van", LastName = "DilenManager", Email = "*****@*****.**", MobileNumber = "011111111111", PhoneNumber = "222222222" } }, CompanyNumber = "55555555", Name = "Cocacola Turnhout", Website = "CocColaTurnhout.be", BtwNumber = "BE 444444444", Email = "*****@*****.**", ExtraInfo = "dit is extrainfo over coca cola turnhout", CmpIBANs = new List <CmpIBAN>() { new CmpIBAN { Number = "222-22222-22-222", IsDefault = true } }, CmpSites = new List <CmpSite>() { new CmpSite() { IsDefault = true, CmpSiteAddress = new CmpSiteAddress() { Street = "druivenstraat", HouseNumber = 55, HouseNumberAddition = "22", Country = "Belgie", Zipcode = "2300", City = "Turnhout" }, Fax = "1111111111", PhoneNumber = "4444444444", PhoneNumber_2 = "2222222222", MobileNumber = "55555555", Email = "*****@*****.**", ExtraInfo = "extra info over hoofdsite van cococola Turnhout", CmpSiteContactPersons = new List <CmpSiteContactPerson>() { new CmpSiteContactPerson() { FirstName = "TomCocaColaContact", //NameAddition = "van", LastName = "DilenContact", Email = "*****@*****.**", MobileNumber = "011111111111", PhoneNumber = "222222222", IsDefault = true, ExtraInfo = "geen extra info over dez contactpersoon" } }, }, }, }; appRespository.Supplier.Add(supCocaCola); //======================================================================================== Supplier supKenField = new Supplier() { CmpManagers = new List <CmpManager>() { new CmpManager() { FirstName = "Ken", //NameAddition = "van", LastName = "Field", Email = "*****@*****.**", MobileNumber = "0478670924", //PhoneNumber = "222222244522" } }, CompanyNumber = "000111222", Name = "KenFieldSupplier", Website = "KenFieldSupplier.be", BtwNumber = "BE 4555588", Email = "*****@*****.**", ExtraInfo = "Teacher .Net developper at Multimedi", CmpIBANs = new List <CmpIBAN>() { new CmpIBAN { Number = "2222222222", IsDefault = true } }, CmpSites = new List <CmpSite>() { new CmpSite() { IsDefault = true, CmpSiteAddress = new CmpSiteAddress() { Street = "Avenue de Kenfield", HouseNumber = 55, //HouseNumberAddition = "22", Country = "KenLand", Zipcode = "9999", City = "Fieldegem" }, Fax = "222222222", PhoneNumber = "0478670924", }, }, }; appRespository.Supplier.Add(supKenField); #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Clients --------------------------------- Client client_TimAudenaarde = new Client { IsActive = true, CltWebCredentials = new CltWebCredentials() { Password = "******", UserName = "******", InlogAttempts = 0, IsBlocked = false, IsPaswordResseted = false, LastResetted = DateTime.Now, }, FirstName = "Tim", //NameAddition , LastName = "Audenaarde", Email = "*****@*****.**", MobileNumber = "0123456", PhoneNumber = "", DateOfBirth = new DateTime(1980, 04, 01), IsMale = true, CltAddresss = new List <CltAddress>() { new CltAddress() { Street = "TimseSteenweg", HouseNumber = 33, HouseNumberAddition = "b3", Country = "Belgie", Zipcode = "1000", City = "Bornem" } }, }; appRespository.Client.Add(client_TimAudenaarde); //================================================================================== Client client_KennyBruwier = new Client { IsActive = true, CltWebCredentials = new CltWebCredentials() { Password = "******", UserName = "******", InlogAttempts = 0, IsBlocked = false, IsPaswordResseted = false, LastResetted = DateTime.Now, }, FirstName = "Kenny", //NameAddition , LastName = "Bruwier", Email = "kweetnognie", MobileNumber = "2222222", PhoneNumber = "014555555", DateOfBirth = new DateTime(1975, 04, 01), IsMale = true, CltAddresss = new List <CltAddress>() { new CltAddress() { Street = "Avenue le Kennedy", HouseNumber = 66, //HouseNumberAddition = "b3", Country = "Belgie", Zipcode = "1000", City = "RupelMonde" } }, }; appRespository.Client.Add(client_KennyBruwier); #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Products--------------------------------- Product product_Spaghetti = new Product() { //--------- id = EAN (geen oplopend nummer) EAN = "1111111111", ProductTitle = "Spaghetti Bolognaise", //ExtraInfo = "", SellingPriceRecommended = 5.22f, CountInStock = 0, MinCountInStock = 100, MaxCountInStock = 500, WareHouseLocation = "H44,01", BTWpercentage = 6, Id_ProductType = 2, //producType 1=Speelgoed, 2=Voedingswaren 3=Autoonderdelen //Image }; appRespository.Product.Add(product_Spaghetti); Product product_Ballenbad = new Product() { //--------- id = EAN (geen oplopend nummer) EAN = "222222222", ProductTitle = "Ballen bad", //ExtraInfo = "", SellingPriceRecommended = 105.22f, CountInStock = 0, MinCountInStock = 5, MaxCountInStock = 10, WareHouseLocation = "H44,02", BTWpercentage = 21, Id_ProductType = 1, //producType 1=Speelgoed, 2=Voedingswaren 3=Autoonderdelen //Image }; appRespository.Product.Add(product_Ballenbad); Product product_DoosLego = new Product() { //--------- id = EAN (geen oplopend nummer) EAN = "33333333", ProductTitle = "Lego StormMinds", //ExtraInfo = "", SellingPriceRecommended = 205.22f, CountInStock = 0, MinCountInStock = 6, MaxCountInStock = 20, WareHouseLocation = "H20,01", BTWpercentage = 21, Id_ProductType = 1, //producType 1=Speelgoed, 2=Voedingswaren 3=Autoonderdelen //Image Supplier_Product_Prices = new List <Supplier_Product_Price>() { new Supplier_Product_Price() { UnitPrice = 44.44f, Id_Supplier = 1, EAN_Product = "222222222" } } }; appRespository.Product.Add(product_DoosLego); Product product_NummerPlatenAuto = new Product() { //--------- id = EAN (geen oplopend nummer) EAN = "444444444", ProductTitle = "Nummerplaat", //ExtraInfo = "", SellingPriceRecommended = 15.99f, CountInStock = 0, MinCountInStock = 20, MaxCountInStock = 80, WareHouseLocation = "H47,02", BTWpercentage = 21, Id_ProductType = 3, //producType 1=Speelgoed, 2=Voedingswaren 3=Autoonderdelen //Image }; appRespository.Product.Add(product_NummerPlatenAuto); #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add OrdersIn -------------------------------- OrderIn bestellengOut_1 = new OrderIn() { Id_OrderedBy = 1, Id_Supplier = 1, OrderedAt = DateTime.Now, OrderLineIns = new List <OrderLineIn>() { new OrderLineIn() { EAN_Product = "222222222", UnitPrice = 22.2f, NumberOfProducts = 5 }, new OrderLineIn() { EAN_Product = "444444444", UnitPrice = 33.2f, NumberOfProducts = 5 } } }; appRespository.OrderIn.Add(bestellengOut_1); #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add OrdersOut-------------------------------- OrderOut bestelling_In1 = new OrderOut() { Id_Client = 1, OrderLineOuts = new List <OrderLineOut>() { new OrderLineOut() { EAN_Product = "222222222", UnitPrice = 22.33f, NumberOfProducts = 4 }, new OrderLineOut() { EAN_Product = "444444444", UnitPrice = 22.33f, NumberOfProducts = 4 } } }; appRespository.OrderOut.Add(bestelling_In1); #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Quatations------------------------------- ProductQuotation quotation1 = new ProductQuotation() { UnitPrice = 10.20f, DateQuatation = DateTime.Now, ExtraInfo = "goei materiaal", EAN_Product = "8888888", Id_Supplier = 1 }; appRespository.ProductQuotation.Add(quotation1); //ProductQuotation quotation2 = new ProductQuotation() //{ // UnitPrice = 10.20f, // DateQuatation = DateTime.Now, // //DateRegistered = // ExtraInfo = "", // Id_Product = 2 //}; //appRespository.ProductQuotation.Add(quotation2); #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Departments------------------------------ #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Departments------------------------------ #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Departments------------------------------ #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Departments------------------------------ #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Departments------------------------------ #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Departments------------------------------ #endregion -------------------------------------------------------------------------------------- #region ------------------------------------------- Add Departments------------------------------ #endregion -------------------------------------------------------------------------------------- //} //catch (Exception ex) //{ // System.Windows.Forms.MessageBox.Show(ex.Message); //} } } }
private void SaveToDB(object obj) { foreach (var item in OrdersInSelected) { if (item.SettedCount < 1) { MessageBox.Show($"u diente een numerieke waarde in te geven dat hoger" + $" ligt dan 0 in de kolom 'Aantal' in rij '{item.ProductName}'", "validatie fout", MessageBoxButton.OK, MessageBoxImage.Error); return; } } //orderins opbouwen //============================ var idsSuppliers = OrdersInSelected.Select(x => x.ID_supplier).Distinct(); List <OrderIn> lstOrderInsBuilded = new List <OrderIn>(); foreach (var item in idsSuppliers) { OrderIn newOrder = new OrderIn() { Id_OrderedBy = _appDbRespository.Employee.InloggedEmployee.Id, Id_Supplier = item, OrderedAt = DateTime.Now, }; newOrder.OrderLineIns = new List <OrderLineIn>(); foreach (var ordselctd in OrdersInSelected) { if (ordselctd.ID_supplier == item) { newOrder.OrderLineIns.Add( new OrderLineIn() { EAN_Product = ordselctd.EAN, UnitPrice = ordselctd.UnitPrice, NumberOfProducts = ordselctd.SettedCount }); } } lstOrderInsBuilded.Add(newOrder); } //messagebox string opbouwen (ook test) //========================================== StringBuilder sb = new StringBuilder(); foreach (var buildedOrder in lstOrderInsBuilded) { sb.Append("\n" + OrdersInSelected.Where(x => x.ID_supplier == buildedOrder.Id_Supplier).Select(x => x.Name_supplier).FirstOrDefault() + "\n"); sb.Append("===============================\n"); foreach (var item in buildedOrder.OrderLineIns) { sb.Append($"Aantal: {item.NumberOfProducts} \tEAN: {item.EAN_Product} \n"); } } //save to db //========== if (MessageBoxResult.Yes == MessageBox.Show("wil je de volgende bestellingen verzenden naar de leverancier(s)?\n" + sb.ToString(), "Verzend Bestellingen naar leverancier", MessageBoxButton.YesNo, MessageBoxImage.Question)) { foreach (var item in lstOrderInsBuilded) { try { _appDbRespository.OrderIn.Add(item); } catch (Exception ex) { MessageBox.Show(ex.Message + ex.InnerException); return; } MessageBox.Show("Bestellingen met succes geregistreerd"); } RefreschData(); } }
public async Task <IHttpActionResult> PostOrder(OrderIn orderIn) { long shopId = orderIn.ShopId; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } foreach (var products in orderIn.Products) { Product product = await db.Products.FindAsync(products.ProductId); if (product == null) { return(ResponseMessage(getHttpResponse(HttpStatusCode.NotFound))); } if (product.Stock <= 0) { return(ResponseMessage(getHttpResponse(HttpStatusCode.Gone))); } if (product.Stock - products.Quantity < 0) { return(ResponseMessage(getHttpResponse(HttpStatusCode.Forbidden))); } if (product.ShopId != shopId) { return(ResponseMessage(getHttpResponse(HttpStatusCode.Unauthorized))); } } foreach (var products in orderIn.Products) { await DecreaseStock(products.ProductId, products.Quantity); } Order newOrder = new Order(); newOrder.CustomerId = orderIn.CustomerId; newOrder.ShippingAddress = orderIn.ShippingAddress; newOrder.BillingAddress = orderIn.BillingAddress; DateTime now = DateTime.Now; newOrder.CreatedAt = now; newOrder.UpdatedAt = now; newOrder.Status = 0; newOrder.ShopId = shopId; float price = 0; foreach (var product in orderIn.Products) { price += (float)((await db.Products.FindAsync(product.ProductId)).Price * product.Quantity); } newOrder.Amount = price; db.Orders.Add(newOrder); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { throw; } if (orderIn.Products != null) { foreach (var productsIn in orderIn.Products) { OrdersToProduct newOrdersToProducts = new OrdersToProduct(); newOrdersToProducts.OrderId = newOrder.Id; newOrdersToProducts.ProductId = productsIn.ProductId; newOrdersToProducts.Quantity = productsIn.Quantity; db.OrdersToProducts.Add(newOrdersToProducts); } } try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(CreatedAtRoute("WSApi", new { id = newOrder.Id }, newOrder)); }