1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using OOO_WriteAndClear.DBModels;
- using OOO_WriteAndClear.MVP.MVPInterfaces;
- using System.Windows;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OOO_WriteAndClear.MVP.Models
- {
- public class OrderCartWindowModel : IOrderCartWindowContract.IModel
- {
- public OrderCartWindowModel() { }
- public OrderFormerer.OrderFormerer OrderFormerer { get; set; }
- #region Реализация IOrderCartWindowContract.IModel
- public void AddProductUnitIntoOrder(string productArticle)
- {
- Product? product = GetProductByArticle(productArticle);
- if (product is null)
- return;
- OrderFormerer.AddProductUnitIntoOrder(product);
- }
- public void RemoveProductFromOrder(string productArticle)
- {
- Product? product = GetProductByArticle(productArticle);
- if (product is null)
- return;
- OrderFormerer.RemoveProductFromOrder(product);
- }
- public void RemoveProductUnitFromOrder(string productArticle)
- {
- Product? product = GetProductByArticle(productArticle);
- if (product is null)
- return;
- OrderFormerer.RemoveProductUnitFromOrder(product);
- }
- public ICollection<PickupPoint> GetAllPickupPoints()
- {
- using (VorobiewTradeContext db = new VorobiewTradeContext())
- {
- return db.PickupPoints.ToList();
- };
- }
- public void AddOrderInSystem(PickupPoint selectedPickupPoint)
- {
- OrderFormerer.Order.OrderPickupPoint = selectedPickupPoint;
- User currentUser = (User)Application.Current.Resources["CurrentUser"];
- if (currentUser.UserId == -1)
- OrderFormerer.Order.OrderCustomer = "";
- else
- OrderFormerer.Order.OrderCustomer = currentUser.ToString();
- Order AddingOrder = OrderFormerer.PrepareOrderForAdd();
- using (VorobiewTradeContext db = new VorobiewTradeContext())
- {
- db.Orders.Add(AddingOrder);
- db.SaveChanges();
- }
- OrderFormerer.Order.OrderId = AddingOrder.OrderId;
- }
- #endregion
- private Product? GetProductByArticle(string article)
- {
- using (VorobiewTradeContext db = new VorobiewTradeContext())
- return db.Products.Find(article);
- }
- }
- }
|