Esempio n. 1
0
 public SaleInfo(DateTime date, FileInformation fileInformation, Client client, Product product, decimal cost)
 {
     this.Date = date;
     this.FileInformation = fileInformation;
     this.Client = client;
     this.Product = product;
     this.Cost = cost;
 }
Esempio n. 2
0
 public SaleInfo(DateTime date, Client client, Product product, decimal cost, int id = 0)
 {
     Date = date;
     Client = client;
     Product = product;
     Cost = cost;
     Id = id;
 }
Esempio n. 3
0
 public SaleInfo(DateTime date, Client client, Product product, FileInfo fileInfo, int cost, string currency, int id = 0)
 {
     Date = date;
     Client = client;
     Product = product;
     FileInfo = fileInfo;
     Cost = cost;
     Currency = currency;
     Id = id;
 }
Esempio n. 4
0
        public void AddSale(SaleDto saleDto)
        {
            lock (_objLock)
            {
                var manager = new DAL.Models.Manager()
                {
                    SecondName = saleDto.Manager
                };
                var client = new DAL.Models.Client()
                {
                    FullName = saleDto.Client
                };
                var product = new DAL.Models.Product()
                {
                    Name = saleDto.Product
                };
                var managerId = _unitOfWork.Managers.GetId(manager);
                if (managerId == null)
                {
                    _unitOfWork.Managers.Create(manager);
                    _unitOfWork.Save();
                    managerId = _unitOfWork.Managers.GetId(manager);
                }

                var clientId = _unitOfWork.Clients.GetId(client);
                if (clientId == null)
                {
                    _unitOfWork.Clients.Create(client);
                    _unitOfWork.Save();
                    clientId = _unitOfWork.Clients.GetId(client);
                }

                var productId = _unitOfWork.Products.GetId(product);
                if (productId == null)
                {
                    _unitOfWork.Products.Create(product);
                    _unitOfWork.Save();
                    productId = _unitOfWork.Products.GetId(product);
                }
                var sale = new DAL.Models.SaleInfo()
                {
                    ClientId  = (int)clientId,
                    ManagerId = (int)managerId,
                    ProductId = (int)productId,
                    Date      = saleDto.Date,
                    Amount    = saleDto.Amount
                };
                _unitOfWork.SalesInfo.Create(sale);
                _unitOfWork.Save();
            }
        }
Esempio n. 5
0
        public void AddToDatabase(InfoList infoList)
        {
            lock (obj)
            {
                var newManager = new DAL.Models.Manager
                {
                    ManagerName = infoList.ManagerName
                };
                var manager = _managerRepository.GetEntity(newManager);
                if (manager == null)
                {
                    _managerRepository.Add(newManager);
                    _managerRepository.SaveChanges();
                    manager = _managerRepository.GetEntity(newManager);
                }

                var newClient = new DAL.Models.Client
                {
                    ClientName = infoList.ClientName
                };
                _clientRepository.Add(newClient);
                _clientRepository.SaveChanges();
                var client = _clientRepository.GetEntity(newClient);

                var newProduct = new DAL.Models.Product
                {
                    ProductName = infoList.ProductName, ProductCost = infoList.ProductCost
                };
                _productRepository.Add(newProduct);
                _productRepository.SaveChanges();
                var product = _productRepository.GetEntity(newProduct);

                var saleInfo = new DAL.Models.SaleInfo
                {
                    SaleDate   = infoList.SaleDate,
                    ID_Manager = manager.ID_Manager,
                    ID_Client  = client.ID_Client,
                    ID_Product = product.ID_Product
                };
                _saleInfoRepository.Add(saleInfo);
                _saleInfoRepository.SaveChanges();
            }
        }
Esempio n. 6
0
        public SaleInfo ParseRecord(Record record)
        {
            string[] strings = record.Client.Split(' ');

            DateTime date = record.Date;
            DAL.Models.FileInformation fileInformation = null;
            Client client = null;
            Product product = new Product(record.Product);
            decimal cost = record.Cost;

            switch (strings.Length)
            {
                case 1:
                    client = new Client("", strings[0]);
                    break;
                case 2:
                    client = new Client(strings[0], strings[1]);
                    break;
            }

            return new SaleInfo(date, fileInformation, client, product, cost);
        }
Esempio n. 7
0
 public SaleInfo(int id, DateTime date, FileInformation fileInformation, Client client, Product product, decimal cost)
     : this(date, fileInformation, client, product, cost)
 {
     this.Id = id;
 }