public async Task <bool> AddTravelerAsync(Guid travelPlanId, Guid userToAddId)
        {
            try
            {
                //check if travelplan exists
                var travelPlan = await _dbContext.TravelPlans.FindAsync(travelPlanId);

                if (travelPlan == null)
                {
                    throw new Exception("Travel Plan Not Found");
                }

                var newUserTravelPlan = new UserTravelPlan
                {
                    UserId       = userToAddId,
                    TravelPlanId = travelPlanId
                };

                //could throw exception if traveler is already added to travel plan bc of the composite key constraint
                _dbContext.UserTravelPlans.Add(newUserTravelPlan);
                var isSuccessful = await _dbContext.SaveChangesAsync() > 0;

                return(isSuccessful);
            }
            catch
            {
                throw;
            }
        }
Esempio n. 2
0
        public async Task <bool> Delete(UserTravelPlan userTPToRemove)
        {
            //remove entry tying user to TP
            _dbContext.UserTravelPlans.Remove(userTPToRemove);
            var isSuccessful = await _dbContext.SaveChangesAsync() > 0;

            return(isSuccessful);
        }
        public async Task <bool> Delete(UserTravelPlan userTPToRemove)
        {
            try
            {
                var isSuccessful = await _userTravelPlanRepository.Delete(userTPToRemove);

                return(isSuccessful);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 4
0
        public async Task <TravelPlanDto> CreateAsync(TravelPlanDto travelPlanDto, Guid userId)
        {
            try
            {
                //map here
                var newTravelPlan = new TravelPlan
                {
                    Name               = travelPlanDto.Name,
                    Description        = travelPlanDto.Description,
                    StartDate          = travelPlanDto.StartDate,
                    EndDate            = travelPlanDto.EndDate,
                    CreatedById        = userId,
                    TravelPlanStatusId = (int)TravelPlanStatusEnum.Created
                };

                await _dbContext.TravelPlans.AddAsync(newTravelPlan);

                //add to jxn table
                var traveler = new UserTravelPlan
                {
                    TravelPlan = newTravelPlan,
                    UserId     = userId
                };

                await _dbContext.UserTravelPlans.AddAsync(traveler);

                var isSuccessful = await _dbContext.SaveChangesAsync() > 0;

                if (isSuccessful)
                {
                    return(new TravelPlanDto(newTravelPlan));
                }
                throw new Exception("Problem Editing Travel Plan");
            }
            catch (Exception exc)
            {
                throw;
            }
        }