public void FillDatabaseWithUsers() { var context = new FoodOrderDbContext().CreateDbContext(null); var repo = new FoodOrderRepository(context); var prevCount = repo.All <User>().Count(); repo.InsertAsync( new[] { new User { Email = "*****@*****.**", UserName = "******" }, new User { Email = "*****@*****.**", UserName = "******" }, new User { Email = "*****@*****.**", UserName = "******" }, new User { Email = "*****@*****.**", UserName = "******" } }); repo.Save(); var currentCount = repo.All <User>().Count(); var diff = currentCount - prevCount; Assert.Equal(4, diff); }
public IActionResult Pay(int orderId) { FoodOrder foodOrder = dbFoodOrder.GetWholeEntity(orderId); if (foodOrder.TotalCost > foodOrder.Customer.Balance) { return(new ObjectResult("You can not pay, your balance is less that total cost!")); } int newBalance = MainLogic.RefreshBalance((int)foodOrder.Customer.Balance, -foodOrder.TotalCost); Customer customer = foodOrder.Customer; customer.Balance = newBalance; dbCustomer.Update(customer); dbCustomer.Save(); //dbFoodOrder.Delete(orderId); dbFoodOrder.Save(); return(new ObjectResult("Succesful pay!")); }
public IActionResult Create([FromBody] FoodOrder foodOrder) { if (!ModelState.IsValid) { return(BadRequest()); } string userJWTId = User.FindFirst("id")?.Value; Customer customer = dbFoodOrder.GetCustomer(userJWTId); if (customer != null) { foodOrder.CustomerId = customer.Id; } //foodOrder.Customer = dbCustomer.GetEntity(foodOrder.CustomerId); Cart cart = dbFoodOrder.GetCart(foodOrder); foodOrder.AddressId = cart.AddressId; foodOrder.DeliveryDate = cart.DeliveryDate; foodOrder.TotalCost = ml.GetTotalCost(foodOrder); dbFoodOrder.Create(foodOrder); dbFoodOrder.Save(); foodOrder.Customer = null; return(Ok(foodOrder)); }
public IActionResult ChangeCaloricGoal(int customerId, int caloricValue) { if (caloricValue <= 0) { return(new ObjectResult("caloricValue must be positive!")); } Customer customer = db.GetEntity(customerId); customer.CaloricGoal = caloricValue; db.Update(customer); db.Save(); fo.Save(); return(new ObjectResult("Succesful operation!")); }