示例#1
0
        private async Task ProcessAsync(EShopType shopType)
        {
            var bufferedData = await _bufferService.GetBufferAsync(shopType);

            await _bufferService.ClearBufferAsync(shopType);

            if (bufferedData.Count == 0)
            {
                return;
            }
            var transaction = await _transactionFactory.CreateAsync(bufferedData[0].ClientCity,
                                                                    bufferedData[0].TransactionDateTime, bufferedData[0].PaymentType, bufferedData[0].ClientPostCode);

            var shop = await _shopFactory.CreateAsync(bufferedData[0].ShopName, bufferedData[0].ShopType, bufferedData[0].ShopPostCode, bufferedData[0].ShopCity);

            shop.Transactions.Add(transaction);
            transaction.Shop = shop;
            foreach (var rawData in bufferedData)
            {
                var product = await _productFactory.CreateAsync(rawData.Price, rawData.Product, rawData.Quantity);

                var transactionProduct = await _transactionProductFactory.CreateAsync(product, transaction);

                transaction.TransactionProducts.Add(transactionProduct);
                product.TransactionProducts.Add(transactionProduct);
                await _productRepository.AddAsync(product);

                await _transactionProductRepository.AddAsync(transactionProduct);
            }
            await _transactionRepository.AddAsync(transaction);

            await _shopRepository.AddAsync(shop);

            await _unitOfWork.SaveAsync();
        }
示例#2
0
        public async Task <Guid> RegisterAsync(Guid shopId, CreateShop createShop)
        {
            var shop = await _shopRepository.GetAsync(shopId);

            if (shop != null)
            {
                throw new ServiceException(ErrorCodes.ShopExist,
                                           $"Shop with id: '{shop.Id}' already exists.");
            }

            var responsiblePerson = _mapper.Map <PersonDto, Person>(createShop.ResponsiblePerson);

            shop = new Shop(shopId, createShop.Address, responsiblePerson, createShop.SID, createShop.Phone);
            await _shopRepository.AddAsync(shop);

            return(_mapper.Map <Guid, Guid>(shop.Id));
        }
        public async Task <int> Handle(CreateShopCommand request, CancellationToken cancellationToken)
        {
            try
            {
                cancellationToken.ThrowIfCancellationRequested();
                await Task.Delay(1000, cancellationToken);
            }
            catch (Exception ex) when(ex is TaskCanceledException)
            {
                throw new TaskCanceledException("The user has cancelled the task!");
            }
            var shop = new Shop
            {
                Name      = request.Name,
                LocationX = request.LocationX,
                LocationY = request.LocationY
            };
            await repository.AddAsync(shop);

            return(shop.Id);
        }
示例#4
0
        public async Task SeedAsync()
        {
            Logger.Info("Initializing data...");
            var tasks = new List <Task>();

            tasks.Add(_userService.RegisterAsync(Guid.NewGuid(), "*****@*****.**", "lukasz", "test", "admin"));
            tasks.Add(_userService.RegisterAsync(Guid.NewGuid(), "*****@*****.**", "marek", "test", "serviceman"));
            tasks.Add(_userService.RegisterAsync(Guid.NewGuid(), "*****@*****.**", "pawel", "test", "servicecoordinator"));
            Logger.Info("Created users: admin, serviceman, servicecoordinator");

            List <Device> devices = new List <Device>()
            {
                new Device(Guid.NewGuid(), "ab12", DateTime.Now, DateTime.Now,
                           new Shop(Guid.NewGuid(), "Toruñ Kwiatowa 18/4",
                                    new Person("£ukasz", "Zieliñski", "*****@*****.**", "530230655"),
                                    "001", "520640330")),
                new Device(Guid.NewGuid(), "bc34", DateTime.Now, DateTime.Now.AddDays(-1),
                           new Shop(Guid.NewGuid(), "Bydgoszcz Polna 22/4",
                                    new Person("Marek", "Kowalski", "*****@*****.**", "540270695"),
                                    "002", "524740360")),
                new Device(Guid.NewGuid(), "b69", DateTime.Now.AddDays(-1), DateTime.Now,
                           new Shop(Guid.NewGuid(), "Warszwa Jana III Sobieskiego 12/3",
                                    new Person("Pawe³", "Wiœniewski", "*****@*****.**", "560260895"),
                                    "003", "524745360"))
            };

            List <ServiceOrder> serviceOrders = new List <ServiceOrder>()
            {
                new ServiceOrder(Guid.NewGuid(),
                                 new Person("£ukasz", "Zieliñski", "*****@*****.**", "530230655"),
                                 new Person("Pawe³", "Wiœniewski", "*****@*****.**", "560360895")),
                new ServiceOrder(Guid.NewGuid(),
                                 new Person("£ukasz", "Zieliñski", "*****@*****.**", "530230655"),
                                 new Person("Marek", "Kowalski", "*****@*****.**", "540270495")),
                new ServiceOrder(Guid.NewGuid(),
                                 new Person("£ukasz", "Zieliñski", "*****@*****.**", "53023655"),
                                 new Person("Marcin", "Wolski", "*****@*****.**", "560230895")),
                new ServiceOrder(Guid.NewGuid(),
                                 new Person("£ukasz", "Zieliñski", "*****@*****.**", "53023655")),
                new ServiceOrder(Guid.NewGuid(),
                                 new Person("£ukasz", "Zieliñski", "*****@*****.**", "53023655"))
            };

            serviceOrders[0].AddServiceOrderDescription("Naprawa Wilanoska 36", "Urz¹dznie mia³o problem z po³aczeniem internetowym. " +
                                                        "Problem ze statycznymi adresami IP zosta³ rozwi¹zany. Wina po stronie klinta.",
                                                        new Person("Pawe³", "Wiœniewski", "*****@*****.**", "560360895"), "true");
            serviceOrders[1].AddServiceOrderDescription("Brak danych", "Urz¹dznie nie wysy³a³o danych. " +
                                                        "Problem z niepoprawn¹ konfiguracj¹ urz¹dzenia. Wina po naszej stronie.",
                                                        new Person("Marek", "Kowalski", "*****@*****.**", "540270495"), "true");
            serviceOrders[2].AddServiceOrderDescription("Warszawa PL35", "Uszkodzona karta SD. " +
                                                        "Nowa karta zostanie wys³ana do klinta i zamontowana. Naprawa w raczej ramach gwarncji, " +
                                                        "aczkolwiek karta mog³abyæ naruszona przez klinta.",
                                                        new Person("Marek", "Kowalski", "*****@*****.**", "540270495"), "false");
            //serviceOrders[2].AddServiceOrderDescription("Warszawa PL35", "Uszkodzona karta SD. " +
            //    "Klient dosta³ i wymini³ kartê. Urzadzenie dzia³a poprawnie.",
            //    new Person("Marek", "Kowalski", "*****@*****.**", "540270495"),true);

            devices[0].AddServiceOrder(serviceOrders[0]);
            devices[1].AddServiceOrder(serviceOrders[1]);
            devices[2].AddServiceOrder(serviceOrders[2]);
            devices[2].AddServiceOrder(serviceOrders[2]);

            foreach (var serviceOrder in serviceOrders)
            {
                await _serviceOrderRepository.AddAsync(serviceOrder).ConfigureAwait(false);
            }

            foreach (var device in devices)
            {
                await _deviceRepository.AddAsync(device);
            }

            Logger.Info("Add serviceOrders with ServiceOrderDescriptions");

            foreach (var device in await _deviceRepository.GetAllAsync())
            {
                _shopRepository.AddAsync(device.Shop);
                _shopRepository.AddShopTime(device.Shop.Id, DayOfWeek.Monday, "10:00", "18:00");
                _shopRepository.AddShopTime(device.Shop.Id, DayOfWeek.Tuesday, "10:00", "18:00");
                _shopRepository.AddShopTime(device.Shop.Id, DayOfWeek.Wednesday, "10:00", "18:00");
                _shopRepository.AddShopTime(device.Shop.Id, DayOfWeek.Thursday, "10:00", "18:00");
                _shopRepository.AddShopTime(device.Shop.Id, DayOfWeek.Friday, "10:00", "18:00");
                _shopRepository.AddShopTime(device.Shop.Id, DayOfWeek.Saturday, "10:00", "18:00");
                _shopRepository.AddShopTime(device.Shop.Id, DayOfWeek.Saturday, "10:00", "18:00");
            }
            Logger.Info("Add shops and set shopTimes");

            await Task.WhenAll(tasks);

            Logger.Info("Data was initialized.");
        }
示例#5
0
        public async Task <ApiResult <AddShopOutput> > GetAll([FromBody] AddShopInput input, CancellationToken cancelToken)
        {
            if (Authorization == null)
            {
                return(new ApiResult <AddShopOutput>(APIResultCode.Unknown, new AddShopOutput {
                }, APIResultMessage.TokenNull));
            }
            var user = _tokenRepository.GetUser(Authorization);

            if (user == null)
            {
                return(new ApiResult <AddShopOutput>(APIResultCode.Unknown, new AddShopOutput {
                }, APIResultMessage.TokenError));
            }
            if (string.IsNullOrWhiteSpace(input.Name))
            {
                return(new ApiResult <AddShopOutput>(APIResultCode.Success_NoB, new AddShopOutput {
                }, "商户名称为空!"));
            }
            if (string.IsNullOrWhiteSpace(input.PhoneNumber))
            {
                return(new ApiResult <AddShopOutput>(APIResultCode.Success_NoB, new AddShopOutput {
                }, "商户手机号为空!"));
            }

            if (string.IsNullOrWhiteSpace(input.Address))
            {
                return(new ApiResult <AddShopOutput>(APIResultCode.Success_NoB, new AddShopOutput {
                }, "地址为空!"));
            }
            if (string.IsNullOrWhiteSpace(input.MerchantCategoryValue))
            {
                return(new ApiResult <AddShopOutput>(APIResultCode.Success_NoB, new AddShopOutput {
                }, "商超类别为空!"));
            }
            if (string.IsNullOrWhiteSpace(input.QualificationImageUrl))
            {
                return(new ApiResult <AddShopOutput>(APIResultCode.Success_NoB, new AddShopOutput {
                }, "资质图片为空!"));
            }


            var merchantCategory = MerchantCategory.GetAll().Where(x => x.Value == input.MerchantCategoryValue).FirstOrDefault();

            if (merchantCategory == null)
            {
                return(new ApiResult <AddShopOutput>(APIResultCode.Success_NoB, new AddShopOutput {
                }, "商超类型不正确!"));
            }

            // var qualificationImage = await _uploadRepository.GetAsync(input.QualificationImageId, cancelToken);
            ShopDto dto = new ShopDto
            {
                Address               = input.Address,
                Description           = input.Description,
                MerchantCategoryValue = merchantCategory.Value,
                MerchantCategoryName  = merchantCategory.Name,
                Name = input.Name,
                QualificationImageUrl = input.QualificationImageUrl,//qualificationImage.Agreement + qualificationImage.Host + qualificationImage.Domain + qualificationImage.Directory + qualificationImage.File,
                OperationTime         = DateTimeOffset.Now,
                OperationUserId       = user.Id.ToString(),
                PhoneNumber           = input.PhoneNumber,
                PrinterName           = input.PrinterName,
                LogoImageUrl          = input.QualificationImageUrl
            };

            //if (!string.IsNullOrWhiteSpace(input.QualificationImageUrl))
            //{
            //    var logoImage = await _uploadRepository.GetAsync(input.LogoImageId, cancelToken);
            dto.LogoImageUrl = input.LogoImageUrl;
            //}
            var entity = await _shopRepository.AddAsync(dto, cancelToken);

            return(new ApiResult <AddShopOutput>(APIResultCode.Success, new AddShopOutput {
                Id = entity.Id.ToString()
            }, APIResultMessage.Success));
        }