Exemplo n.º 1
0
 public static PricingPackageDto MapToDto(PricingPackage pricingPackage)
 {
     return(new PricingPackageDto()
     {
         PricingPackageId = pricingPackage.PricingPackageId,
         PricingPackageName = pricingPackage.PricingPackageName,
         Price = pricingPackage.Price,
         IsActive = pricingPackage.IsActive,
         IsDeleted = pricingPackage.IsDeleted,
         DateCreated = pricingPackage.DateCreated,
         DateModified = pricingPackage.DateModified
     });
 }
        public async Task <bool> CreateOrder(
            [FromHeader] int uid,
            [FromForm] int pricingPackageId,
            [FromForm] string phone,
            [FromForm] string address,
            [FromForm] DateTime time,
            [FromForm] string province,
            [FromForm] string city,
            [FromForm] string area)
        {
            PricingPackage pricingPackage = await dbContext.PricingPackage.FirstOrDefaultAsync(m => m.Id == pricingPackageId);

            if (pricingPackage == null)
            {
                throw new ApiException(HttpResultCode.数据不存在);
            }
            var deposit = await dbContext.SysConfig.FirstOrDefaultAsync(m => m.Key == ReadonlyUtils.SysConfig_deposit);

            var depositValue = deposit == null?0M:decimal.Parse(deposit.Value);
            var user         = await dbContext.UserInfo.FirstOrDefaultAsync(m => m.Id == uid);

            if (user.Point < depositValue)
            {
                throw new ApiException(HttpResultCode.余额不足);
            }
            user.Point -= depositValue;
            OrderList orderList = new OrderList()
            {
                PricingPackageId = pricingPackageId,
                OrderNumber      = StringUtil.GetOrderNumber(),
                Price            = pricingPackage.Price,
                Deposit          = depositValue,
                UserId           = uid,
                Province         = province,
                City             = city,
                Area             = area,
                Address          = address,
                Time             = time,
                Status           = (int)OrderStatus.预约,
                IsTel            = 0,
                CreateTime       = DateTime.Now,
                Phone            = phone
            };

            dbContext.OrderList.Add(orderList);
            await dbContext.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 3
0
        PricingPackageDto IPricingPackageRepository.GetPricingPackage(int pricingPackageId)
        {
            PricingPackage t = _dbContext.PricingPackage.FirstOrDefault(x => x.PricingPackageId == pricingPackageId);

            return(t != null?PricingPackageRepository.MapToDto(t) : null);
        }