Example #1
0
        public async Task <Result> Post(int freightTemplateId, [FromBody] PriceAndDestinationCreateParam model)
        {
            var entity = new PriceAndDestination()
            {
                CountryId         = model.CountryId,
                FreightTemplateId = freightTemplateId,
                MinOrderSubtotal  = model.MinOrderSubtotal,
                StateOrProvinceId = model.StateOrProvinceId,
                ShippingPrice     = model.ShippingPrice,
                Note      = model.Note,
                IsEnabled = model.IsEnabled
            };
            var any = await _priceAndDestinationRepository.Query().AnyAsync(c => c.FreightTemplateId == entity.FreightTemplateId &&
                                                                            c.CountryId == model.CountryId &&
                                                                            c.StateOrProvinceId == model.StateOrProvinceId);

            if (any)
            {
                return(Result.Fail("运费策略已存在,同一国家、省市区运费策略只能存在一个"));
            }

            _priceAndDestinationRepository.Add(entity);
            await _priceAndDestinationRepository.SaveChangesAsync();

            return(Result.Ok());
        }
Example #2
0
        public async Task <IActionResult> Post([FromBody] PriceAndDestinationForm model)
        {
            if (ModelState.IsValid)
            {
                var priceAndDestination = new PriceAndDestination
                {
                    CountryId         = model.CountryId,
                    StateOrProvinceId = model.StateOrProvinceId,
                    MinOrderSubtotal  = model.MinOrderSubtotal,
                    ShippingPrice     = model.ShippingPrice,
                    Note = model.Note
                };

                _priceAndDestinationRepository.Add(priceAndDestination);
                await _priceAndDestinationRepository.SaveChangesAsync();

                return(await Get(priceAndDestination.Id));
            }

            return(BadRequest(ModelState));
        }