Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            Console.Write("Digite o nome do seu produto");

            var input = Console.ReadLine();

            var productName = ProductName
                              .Create(input);

            if (productName.IsSuccess)
            {
                var product = new Product(productName.Value);

                var unitOfWork = new SalesUnitOfWork();

                //var repository = new Repository<Product>(unitOfWork);
                var repository = new ProductRepository(unitOfWork);

                repository.Add(product);

                //unitOfWork.Add(product); //commando de insert do sql server

                unitOfWork.SaveChanges(); //Comando de commit do sql server

                Console.WriteLine("Sucesso!");
            }
            else
            {
                Console.WriteLine(productName.Error);
            }

            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using(var salesUnitOfWork = new SalesUnitOfWork("Sales"))
            {
                var customer = new Customer { FirstName = "John", LastName = "Smith" };

                var order = new Order {Date = DateTime.Now};
                order.OrderItems.Add(new OrderItem {Price = 101});

                customer.Orders.Add(order);

                salesUnitOfWork.Customers.Add(customer);

                salesUnitOfWork.Commit();

                var customers = salesUnitOfWork.Customers
                    .FindAll()
                    .Include("Orders.OrderItems")
                    .Where(c => c.Orders.Any(o => o.OrderItems.Any(oi => oi.Price > 100)))
                    .OrderBy(c => c.FirstName)
                    .Take(10)
                    .ToList();

                foreach (var c in customers)
                {
                    System.Console.WriteLine(c.FirstName);
                    foreach (var o in c.Orders)
                    {
                        System.Console.WriteLine(o.Date);
                    }
                }

            }
        }
Exemplo n.º 3
0
        public async Task <GetProductByIdDto> HandlerAsync(GetProductByIdQuery query)
        {
            var unitOfWork = new SalesUnitOfWork();

            var repository = new ProductRepository(unitOfWork);

            var result = await repository
                         .GetAsync(query.Id);

            if (result == null)
            {
                return(null);
            }

            var dto = new GetProductByIdDto
            {
                Id   = result.Id,
                Name = result.ProductName.Value
            };

            return(dto);
        }
        private void AddSale(object sender, TaskEventArgs arg)
        {
            var handlerArg = arg as TaskHandlerEventArgs;

            foreach (var sale in handlerArg.sales)
            {
                var context = new SalesContext();
                var uow     = new SalesUnitOfWork(context);
                lock (locker)
                {
                    try
                    {
                        uow.AddSale
                        (
                            new Client {
                            Name = sale.CustomerName
                        },
                            new Product {
                            Name = sale.ProductName, Price = sale.ProductPrice
                        },
                            sale.Date
                        );
                        uow.SaveContext();
                        logger.LogInfo(Task.CurrentId + " added sale " + sale.ToString());
                    }
                    catch (Exception)
                    {
                        throw new InvalidOperationException(Task.CurrentId + " failed adding " + sale.ToString() + " from " + handlerArg.fileName);
                    }
                    finally
                    {
                        uow.Dispose();
                    }
                }
            }
        }
Exemplo n.º 5
0
 public UserRepository(SalesUnitOfWork unitOfWork)
     : base(unitOfWork)
 {
 }
Exemplo n.º 6
0
 public HomeController(EmployeeContext context)
 {
     data = new SalesUnitOfWork(context);
 }
Exemplo n.º 7
0
 }                                          //get a copy of database context
 public ValidationController(SalesUnitOfWork data)
 {
     Data = data;
 }
Exemplo n.º 8
0
 public ProductRepository(SalesUnitOfWork unitOfWork)
     : base(unitOfWork)
 {
 }
 public SalesController(EmployeeContext context)
 {
     Data = new SalesUnitOfWork(context);
 }