Example #1
0
        public async Task <int> CreateLocation([FromBody][Required] string name)
        {
            var location = new Location
            {
                Enabled = true,
                Name    = name
            };

            _db.Add(location);
            await _db.SaveChangesAsync();

            return(location.Id);
        }
Example #2
0
        public async Task <FoodOrder> Create(CydcContext db, int userId, FoodOrderClientInfo clientInfo)
        {
            var menu = await db.FoodMenu.FindAsync(MenuId);

            var dateNow   = DateTime.Now;
            var foodOrder = new FoodOrder
            {
                OrderUserId         = userId,
                OrderTime           = dateNow,
                LocationId          = AddressId,
                FoodMenuId          = MenuId,
                TasteId             = TasteId,
                Comment             = Comment,
                FoodOrderClientInfo = clientInfo,
            };

            foodOrder.AccountDetails.Add(new AccountDetails
            {
                UserId     = userId,
                CreateTime = dateNow,
                Amount     = -menu.Price
            });
            db.Add(foodOrder);
            await db.SaveChangesAsync();

            decimal amount = await db.AccountDetails.Where(x => x.UserId == userId).SumAsync(x => x.Amount);

            if (amount >= 0)
            {
                await AutoPay(db, foodOrder);
            }
            return(foodOrder);
        }