Ejemplo n.º 1
0
        public async Task <bool> RemoveCoownerAsync(long ownerId, long restaurantId, long coownerId)
        {
            EmployersRestaurants currentConnection = await CheckEmployerRestaurantAsync(ownerId, restaurantId);

            Employers employerToRemove = await CheckEmployerExistenceAsync(coownerId);

            long count = await EmployerRestaurantRepo.GetNumbetOfEmployers(restaurantId);

            if (count == 1)
            {
                throw new Exception("There's ony one owner to the restaurant. Use Close restaurant instead");
            }

            if (currentConnection.TheEmployer.Id == employerToRemove.Id)
            {
                throw new Exception("The owner cannot remove itself. Use Transfer ownership instead");
            }

            EmployersRestaurants data = await EmployerRestaurantRepo.GetByRestaurantIdAndEmployerId(restaurantId, coownerId);

            if (data == null)
            {
                throw new Exception(String.Format("The given owner with id:{0} can't be removed beacause is not an owner", coownerId));
            }

            await EmployerRestaurantRepo.RemoveAsync(data);

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> TransferOwnershipAsync(long ownerId, long restaurantId, long newOwnerId)
        {
            EmployersRestaurants currentConnection = await CheckEmployerRestaurantAsync(ownerId, restaurantId);

            Employers newEmployer = await CheckEmployerExistenceAsync(newOwnerId);

            EmployersRestaurants oldData = await EmployerRestaurantRepo.GetByRestaurantIdAndEmployerId(restaurantId, ownerId);

            if (oldData == null)
            {
                throw new Exception(String.Format("The given owner with id:{0} is not an owner.", ownerId));
            }

            EmployersRestaurants newData = await EmployerRestaurantRepo.GetByRestaurantIdAndEmployerId(restaurantId, newOwnerId);

            if (newData != null)
            {
                throw new Exception(String.Format("The given new owner with id:{0} is already an owner.", newOwnerId));
            }

            await EmployerRestaurantRepo.AddAsync
            (
                new EmployersRestaurants
            {
                RestaurantId = restaurantId,
                EmployerId   = newOwnerId
            },
                ModifierId
            );

            await EmployerRestaurantRepo.RemoveAsync(oldData);

            return(true);
        }