Beispiel #1
0
        public void AddToDatabase(Journal journal)
        {
            lock (this)
            {
                var newManager = new DAL.Models.Manager { ManagerName = journal.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 = journal.ClientName };
                _clientRepository.Add(newClient);
                _clientRepository.SaveChanges();
                var client = _clientRepository.GetEntity(newClient);

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

                var saleInfo = new DAL.Models.SaleInfo
                {
                    SaleDate = journal.SaleDate,
                    ID_Manager = manager.ID_Manager,
                    ID_Client = client.ID_Client,
                    ID_Product = product.ID_Product
                };
                _saleInfoRepository.Add(saleInfo);
                _saleInfoRepository.SaveChanges();
            }
        }
Beispiel #2
0
 public static DTO.Models.ClientComment ClientCommentDTOToClientCommentDAO(this DAL.Models.Client Client)
 {
     return(new DTO.Models.ClientComment()
     {
         Firstname = Client.Firstname,
         Lastname = Client.Lastname
     });
 }
Beispiel #3
0
        public void Create(DAL.Models.Client itemClient)
        {
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <DAL.Models.Client, Client>()
                                                 .ForMember("Name", opt => opt.MapFrom(c => c.Name))).CreateMapper();
            Client client = mapper.Map <DAL.Models.Client, Client>(itemClient);

            _modelOfSalesContainer.ClientSet.Add(client);
        }
Beispiel #4
0
        public void Send(string managerLastName, SaleInfoRecord item)
        {
            lock (_lockObj)
            {
                using (_unitOfWork = new UnitOfWork())
                {
                    using (var transaction = _unitOfWork.BeginTransaction())
                    {
                        try
                        {
                            DAL.Models.Manager newManager = new DAL.Models.Manager {
                                LastName = managerLastName
                            };
                            Model.Manager manager = _unitOfWork.ManagerRepository.FindBy(m => m.LastName == newManager.LastName);
                            if (manager == null)
                            {
                                _unitOfWork.ManagerRepository.Create(newManager);
                                _unitOfWork.Save();
                                manager = _unitOfWork.ManagerRepository.FindBy(m => m.LastName == newManager.LastName);
                            }

                            DAL.Models.Product newProduct = new DAL.Models.Product {
                                Name = item.Product, Price = item.Price
                            };
                            _unitOfWork.ProductRepository.Create(newProduct);

                            DAL.Models.Client newClient = new DAL.Models.Client {
                                Name = item.Client
                            };
                            _unitOfWork.ClientRepository.Create(newClient);

                            _unitOfWork.Save();

                            Model.Product product = _unitOfWork.ProductRepository.FindBy(p => p.Name == newProduct.Name);
                            Model.Client  client  = _unitOfWork.ClientRepository.FindBy(c => c.Name == newClient.Name);

                            DAL.Models.SaleInfo newSaleInfo = new DAL.Models.SaleInfo
                            {
                                ProductId  = product.ProductId,
                                ClientId   = client.ClientId,
                                ManagerId  = manager.ManagerId,
                                DateOfSale = item.DateOfSale
                            };
                            _unitOfWork.SaleInfoRepository.Create(newSaleInfo);
                            _unitOfWork.Save();
                            transaction.Commit();
                        }
                        catch (Exception e)
                        {
                            transaction.Rollback();
                            throw new Exception(e.Source + " : Crash in sender from " + managerLastName);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public int?GetId(Client client)
        {
            var tmp = _context.Clients.FirstOrDefault(c => (c.FullName == client.FullName));

            if (tmp == null)
            {
                return(null);
            }
            return(tmp.Id);
        }
        public void AddSaleInfo(SaleDTO saleDto)
        {
            lock (_locker)
            {
                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 = _repositories.Managers.GetId(manager);
                if (managerId == null)
                {
                    _repositories.Managers.Add(manager);
                    _repositories.Save();
                    managerId = _repositories.Managers.GetId(manager);
                }

                var clientId = _repositories.Clients.GetId(client);
                if (clientId == null)
                {
                    _repositories.Clients.Add(client);
                    _repositories.Save();
                    clientId = _repositories.Clients.GetId(client);
                }

                var productId = _repositories.Products.GetId(product);
                if (productId == null)
                {
                    _repositories.Products.Add(product);
                    _repositories.Save();
                    productId = _repositories.Products.GetId(product);
                }

                var saleInfo = new DAL.Models.SaleInfo()
                {
                    Date      = saleDto.Date,
                    ManagerId = (int)managerId,
                    ClientId  = (int)clientId,
                    ProductId = (int)productId,
                    Amount    = saleDto.Amount
                };

                _repositories.SalesInfo.Add(saleInfo);
                _repositories.Save();
            }
        }
Beispiel #7
0
 public static DTO.Models.Client ClientDTOToClientDAO(this DAL.Models.Client client)
 {
     if (client == null)
     {
         return(null);
     }
     return(new DTO.Models.Client
     {
         Id = client.Id,
         BirthDate = client.BirthDate,
         Disabled = client.Disabled,
         EmailAddress = client.EmailAddress,
         Firstname = client.Firstname,
         Lastname = client.Lastname,
         PhoneNumber = client.PhoneNumber,
         IdRole = client.IdRole
     });
 }
        public void AddToDatabase(Journal journal)
        {
            lock (this)
            {
                var newManager = new DAL.Models.Manager {
                    ManagerName = journal.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 = journal.ClientName
                };
                _clientRepository.Add(newClient);
                _clientRepository.SaveChanges();
                var client = _clientRepository.GetEntity(newClient);

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

                var saleInfo = new DAL.Models.SaleInfo
                {
                    SaleDate   = journal.SaleDate,
                    ID_Manager = manager.ID_Manager,
                    ID_Client  = client.ID_Client,
                    ID_Product = product.ID_Product
                };
                _saleInfoRepository.Add(saleInfo);
                _saleInfoRepository.SaveChanges();
            }
        }
Beispiel #9
0
 public void Update(Client client)
 {
 }
Beispiel #10
0
 public void Create(Client client)
 {
     _context.Clients.Add(ObjectToEntity(client));
 }
        public void UpdateSaleInfo(SaleDTO saleDto)
        {
            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 = _repositories.Managers.GetId(manager);

            if (managerId == null)
            {
                _repositories.Managers.Add(manager);
                _repositories.Save();
                managerId = _repositories.Managers.GetId(manager);
            }

            var clientId = _repositories.Clients.GetId(client);

            if (clientId == null)
            {
                _repositories.Clients.Add(client);
                _repositories.Save();
                clientId = _repositories.Clients.GetId(client);
            }

            var productId = _repositories.Products.GetId(product);

            if (productId == null)
            {
                _repositories.Products.Add(product);
                _repositories.Save();
                productId = _repositories.Products.GetId(product);
            }

            var saleInfo = new DAL.Models.SaleInfo()
            {
                Date      = saleDto.Date,
                ManagerId = (int)managerId,
                ClientId  = (int)clientId,
                ProductId = (int)productId,
                Amount    = saleDto.Amount
            };

            var sale = _repositories.SalesInfo.GetAll().FirstOrDefault(s => (s.Id == saleDto.Id));

            sale.Date      = saleDto.Date;
            sale.ManagerId = (int)managerId;
            sale.ClientId  = (int)clientId;
            sale.ProductId = (int)productId;
            sale.Amount    = saleDto.Amount;

            _repositories.SalesInfo.Update(sale);
            _repositories.Save();
        }