Exemplo n.º 1
0
 private void SaveOrder(OrderDTO order)
 {
     using (var unitOfWork = _factory.GetInstance())
     {
         unitOfWork.AddOrder(order);
         unitOfWork.Save();
     }
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Get(int id)
        {
            using (var uow = _unitOfWorkFactory.GetInstance())
            {
                var topic = await uow.TopicRepository.GetAsync(id);

                // TODO: Possibly think if null different response.
                return(Ok(topic));
            }
        }
Exemplo n.º 3
0
        public async Task <Page <Customer> > GetAsyncByName(string name, PagingOptions pagingOptions, bool getVehicles = true, SearchVehicleStatus vehicleStatus = SearchVehicleStatus.Any)
        {
            IQueryable <Customer> query;

            using (IDbConnection connection = _customersRepository.Connection)
            {
                query = (await _customersRepository.GetAsyncByName(name)).AsQueryable();
            }

            var size  = query.Count();
            var items = query.ToArray();

            if (getVehicles)
            {
                using (IUnitOfWork uow = _unitOfWorkFactory.GetInstance())
                {
                    foreach (var customer in items)
                    {
                        customer.Vehicles = await uow.VehiclesRepository.GetByCustomerId(customer.Id, vehicleStatus);
                    }
                }
                if (vehicleStatus != SearchVehicleStatus.Any)
                {
                    items = items.Where(c => c.Vehicles != null && c.Vehicles.Count() > 0).ToArray();
                }
            }

            items = items
                    .Skip(pagingOptions.Offset.Value)
                    .Take(pagingOptions.Limit.Value)
                    .ToArray();

            return(new Page <Customer>
            {
                Items = items,
                TotalSize = items.Count()
            });
        }
Exemplo n.º 4
0
        public async Task <bool> Register(string email, string password, string friendlyName)
        {
            if (DoesEmailExists(email) != null)
            {
                var(pword, salt) = _passwordProtectionService.Encrypt(password);
                var user = new User {
                    Password     = pword,
                    Salt         = salt,
                    Email        = email,
                    FreindlyName = friendlyName
                };

                using (var uow = _unitOfWorkFactory.GetInstance())
                {
                    await uow.UserRepository.AddAysnc(user);

                    await uow.CompleteAsync();
                }

                return(true);
            }
            return(false);
        }