public IActionResult GetRestaurant(int accountId, int restaurantId) { if (IsUserAllowedToGet(accountId, restaurantId)) { var restaurant = restaurantsRepository.Find(restaurantId); return(Ok(restaurant)); } return(BadRequest(noRightsForViewing)); }
private bool IsMealModifyingAllow(int accountId, Meal meal) { var account = accountsRepository.Find(accountId); var restaurant = restaurantsRepository.Find(meal.RestaurantId); return(account != null && restaurant != null && account.AccountId == restaurant.OwnerId); }
public async Task UpdateStaus(int accountId, int orderId, OrderStatuses newOrderStatus) { var account = accountsRepositoty.Find(accountId); if (account == null || !IsChangeAllowed(account.Role, newOrderStatus) || !IsNextStep(newOrderStatus, orderId)) { throw new Exception("CantUpdate"); } var newStatus = new OrderStatus() { StatusChangeTime = DateTime.Now, OrderId = orderId, Status = newOrderStatus }; var order = ordersRepository.GetOrderWithStatusAndMeals(orderId); order.LatestOrderStatus = newOrderStatus; order.OrderStatuses.Add(newStatus); ordersRepository.Update(order); var restaurant = restaurantsRepository.Find(order.RestaurantId); await clientCommunicationService.OrderStatusChangedNotify((int)order.CustomerId, orderId, restaurant.OwnerId, newOrderStatus); }
public bool IsUserAllowedForRestaureant(int accountId, int restaurantId) { if (accountId == 0) { return(true); } var account = accountsRepository.Find(accountId); if (account.Role == AccountRoles.RegularUser) { var blokedUserOwners = blockedUsersRepository.BlokedUserOwners(accountId); var restaurant = restaurantsRepository.Find(restaurantId); return(!blokedUserOwners.Any(buo => buo.OwnerId == restaurant.OwnerId)); } else { var restarurants = restaurantsRepository.GetOwnersRestaurants(accountId); return(restarurants.Any(r => r.EntityId == restaurantId)); } }