示例#1
0
        public async Task <Result <ZoneResponse> > GetZoneCoverage(string city,
                                                                   ReceivingType receivingType = ReceivingType.picking)
        {
            try
            {
                var urlParams = $"{city}?type={Enum.GetName(typeof(ReceivingType), receivingType)}";
                var response  = await _webClient.GetAsync($"/v2/areas/{urlParams}").ConfigureAwait(false);

                var result = new Result <ZoneResponse>();

                if (response.IsSuccessStatusCode)
                {
                    result.Data = await response.Content.ReadAsAsync <ZoneResponse>().ConfigureAwait(false);

                    return(result);
                }

                result.Error = response.Content.ReadAsAsync <ErrorResponse>().Result;
                return(result);
            }
            catch (Exception e)
            {
                throw new HttpRequestException($"{nameof(GetZoneCoverage)} failed", e);
            }
        }
示例#2
0
        public async Task <Result <bool> > Validate(string address, ReceivingType receivingType, string phone = "")
        {
            try
            {
                var urlParams = $"?type={Enum.GetName(typeof(ReceivingType), receivingType)}&address={WebUtility.UrlEncode(address)}";
                urlParams += phone != string.Empty ? $"&phone={phone}" : string.Empty;
                var response = await _webClient.GetAsync($"/v2/addresses/validate{urlParams}").ConfigureAwait(false);

                var result = new Result <bool>();

                if (response.IsSuccessStatusCode)
                {
                    var obj = await response.Content.ReadAsAsync <ExpandoObject>().ConfigureAwait(false);

                    result.Data = (bool)obj.FirstOrDefault(x => x.Key == "success").Value;
                    return(result);
                }

                result.Error = response.Content.ReadAsAsync <ErrorResponse>().Result;
                return(result);
            }
            catch (Exception e)
            {
                throw new HttpRequestException($"{nameof(Validate)} failed", e);
            }
        }
示例#3
0
        public IActionResult OnGetLoadReceivingType()
        {
            var receivingType = _receivingTypeRepository.GetAll();

            if (receivingType != null)
            {
                ReceivingTypes = new List <ReceivingType>();
                var items = receivingType.Where(cd => cd.IsDeleted == false).ToList();

                if (items.Count > 0)
                {
                    foreach (var item in items)
                    {
                        var receivingTypes = new ReceivingType
                        {
                            Id            = item.Id,
                            Name          = item.Name,
                            Value         = item.Value,
                            NumberShipDay = item.NumberShipDay
                        };
                        ReceivingTypes.Add(receivingTypes);
                    }
                }
            }
            return(new OkObjectResult(ReceivingTypes));
        }
示例#4
0
        public IActionResult OnPostDelete([FromBody] ReceivingType model)
        {
            var receivingType = _receivingTypeRepository.Find(model.Id);

            _receivingTypeRepository.Delete(receivingType);
            var orders = _orderRepository.GetSome(x => x.ReceivingTypeId == model.Id && x.IsDeleted == false);

            _orderRepository.DeleteRange(orders);
            return(new OkResult());
        }
示例#5
0
        public async Task AddressValidate_Should_ThrowException()
        {
            //Arrange
            const string        address       = "rue de Rivoli 75004 Paris";
            const ReceivingType receivingType = ReceivingType.delivering;

            //Act
            var result = await StuartApi.Address.Validate(address, receivingType).ConfigureAwait(false);

            //Assert
            result.Error.Should().NotBeNull();
        }
示例#6
0
        public async Task AddressValidate_Should_ReturnTrue()
        {
            //Arrange
            const string        address       = "29 rue de Rivoli 75004 Paris";
            const ReceivingType receivingType = ReceivingType.delivering;

            //Act
            var result = await StuartApi.Address.Validate(address, receivingType).ConfigureAwait(false);

            //Assert
            result.Data.Should().BeTrue();
        }
示例#7
0
        public async Task GetZoneCoverage_Should_ReturnCorrectData()
        {
            // Arrange
            const string        city          = "Paris";
            const ReceivingType receivingType = ReceivingType.delivering;

            // Act
            var result = await StuartApi.Address.GetZoneCoverage(city, receivingType).ConfigureAwait(false);

            //Assert
            result.Data.Features.Should().NotBeEmpty();
            result.Data.Type.Should().Be("FeatureCollection");
        }
示例#8
0
        public async Task AddressValidate_Should_ReturnTrue_WhenAddressIsApproxAndPhoneIsProvided()
        {
            //Arrange
            const string        address       = "rue de Rivoli 75004 Paris";
            const ReceivingType receivingType = ReceivingType.delivering;
            const string        phone         = "123456789";

            //Act
            var result = await StuartApi.Address.Validate(address, receivingType, phone).ConfigureAwait(false);

            //Assert
            result.Data.Should().BeTrue();
        }
示例#9
0
        public IActionResult OnPostSaveEntity([FromBody] ReceivingType model)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult("Đã xãy ra lỗi"));
            }

            if (model.Id == 0)
            {
                model.DateCreated = DateTime.Now;
                _receivingTypeRepository.Add(model);
            }
            else
            {
                var receivingType = _receivingTypeRepository.Find(model.Id);
                receivingType.Name          = model.Name;
                receivingType.Value         = model.Value;
                receivingType.NumberShipDay = model.NumberShipDay;
                receivingType.DateModified  = DateTime.Now;
                //item.Description = model.Description;
                //item.Price = model.Price;
                //item.OriginalPrice = model.OriginalPrice;
                //item.DateModified = DateTime.Now;
                _receivingTypeRepository.Update(receivingType);
            }
            //var listImages = _productImagesRepository.GetSome(x => x.ItemId == model.Id);
            //_productImagesRepository.DeleteRange(listImages);
            //var listAttachment = TempData.Get<List<ProductImages>>(CommonConstants.Attachments);
            //if (listAttachment != null && listAttachment.Count > 0)
            //{
            //    foreach (var attachment in listAttachment)
            //    {
            //        string fileName = SaveAttachment(attachment);

            //        if (!string.IsNullOrEmpty(fileName))
            //        {
            //            _productImagesRepository.Add(new ProductImages()
            //            {
            //                ItemId = model.Id,
            //                Name = fileName,
            //                Path = attachment.Path,
            //                Contents = attachment.Contents
            //            });
            //        }
            //    }
            //}

            return(new OkObjectResult(model));
        }