Beispiel #1
0
        public async Task <Result> Put(int id, [FromBody] PriceAndDestinationCreateParam model)
        {
            var entity = await _priceAndDestinationRepository.FirstOrDefaultAsync(id);

            if (entity == null)
            {
                return(Result.Fail("单据不存在"));
            }

            var any = await _priceAndDestinationRepository.Query().AnyAsync(c => c.FreightTemplateId == entity.FreightTemplateId &&
                                                                            c.CountryId == model.CountryId &&
                                                                            c.StateOrProvinceId == model.StateOrProvinceId &&
                                                                            c.Id != entity.Id);

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

            entity.CountryId         = model.CountryId;
            entity.MinOrderSubtotal  = model.MinOrderSubtotal;
            entity.StateOrProvinceId = model.StateOrProvinceId;
            entity.ShippingPrice     = model.ShippingPrice;
            entity.Note      = model.Note;
            entity.IsEnabled = model.IsEnabled;
            entity.UpdatedOn = DateTime.Now;
            await _priceAndDestinationRepository.SaveChangesAsync();

            return(Result.Ok());
        }
Beispiel #2
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());
        }