public void AddOperation(DateTime date, Manager manager, string clientName, string productName, Session session, int price)
        {
            DAL.Client  client  = _salesContext.Clients.FirstOrDefault(x => x.Name == clientName);
            DAL.Product product = _salesContext.Products.FirstOrDefault(x => x.Name == productName);

            if (client == null)
            {
                client = new DAL.Client()
                {
                    Name = clientName
                }
            }
            ;
            if (product == null)
            {
                product = new DAL.Product()
                {
                    Name = productName
                }
            }
            ;

            DAL.Operation operation = new DAL.Operation()
            {
                DateOfOperation = date,
                Manager         = ToEntity(manager),
                Client          = client,
                Product         = product,
                Session         = ToEntity(session),
                Price           = price
            };

            _salesContext.Operations.Add(operation);
            _salesContext.SaveChanges();
        }
     private DAL.Operation ToEntity(Operation operation)
     {
         DAL.Operation operationDAL = operation.Id != 0 ? _salesContext.Operations.FirstOrDefault(x => x.ID == operation.Id) : null;
         if (operationDAL != null)
         {
             return(operationDAL);
         }
         else
         {
             return new DAL.Operation()
                    {
                        Client          = ToEntity(operation.Client),
                        Manager         = ToEntity(operation.Manager),
                        Product         = ToEntity(operation.Product),
                        Price           = operation.Price,
                        DateOfOperation = operation.DateOfOperation,
                        Session         = ToEntity(operation.Session)
                    }
         };
     }
 }
 private Operation ToObject(DAL.Operation operation)
 {
     return(new Operation(operation.ID, operation.DateOfOperation, DataMapper.Mapping(operation.Manager),
                          DataMapper.Mapping(operation.Client), DataMapper.Mapping(operation.Product),
                          DataMapper.Mapping(operation.Session), operation.Price));
 }