public void RegisterRestaurantRole(string userName, Restaurant restaurant, RestaurantMonitor restaurantMonitor) { User user = _dbSet.Find(userName); if (user == null) { user = new User { UserName = userName, RestaurantId = restaurant.RestaurantId, RestaurantMonitorId = restaurantMonitor.RestaurantMonitorId }; _dbSet.Add(user); } else { if ((user.RestaurantId != null) || (user.RestaurantMonitorId != null)) { throw new UserRoleAlreadyExistsException(); } user.RestaurantId = restaurant.RestaurantId; user.RestaurantMonitorId = restaurantMonitor.RestaurantMonitorId; _context.Entry(user).State = EntityState.Modified; } }
public void RegisterRestaurant(string userName, Restaurant restaurant) { restaurant.CreatedAt = DateTime.Now; _unitOfWork.RestaurantRepository.Add(restaurant); RestaurantMonitor restaurantMonitor = new RestaurantMonitor { CreatedAt = DateTime.Now, RestaurantId = restaurant.RestaurantId }; _unitOfWork.RestaurantMonitorRepository.Add(restaurantMonitor); _authorizationManager.RegisterRestaurantRole(userName, restaurant, restaurantMonitor); _unitOfWork.Complete(); }