Esempio n. 1
0
        public async Task <DataResponse> UnsignFromCarpoolEvent(int carpoolConfirmationId)
        {
            using (var context = CreateContext())
            {
                try
                {
                    // Get carpool confirmation
                    CarpoolConfirmation carpoolConfirmation = await context.CarpoolConfirmations.FirstOrDefaultAsync(x => x.Id == carpoolConfirmationId);

                    // Remove carpool confirmation
                    context.CarpoolConfirmations.Remove(carpoolConfirmation);
                    // Save changes
                    int rowsChanged = await context.SaveChangesAsync();

                    // Error when saving
                    if (rowsChanged != 1)
                    {
                        return(new DataResponse(400, Resources.AppResources.could_not_unsign_from_carpool));
                    }
                    // Return response
                    return(new DataResponse(true));
                }
                catch (Exception mes)
                {
                    // Return exception
                    return(new DataResponse(1, mes.Message));
                }
            }
        }
Esempio n. 2
0
        public async Task <DataResponse> AnswerCarpoolConfirmation(int userId, int carpoolConfirmationId, bool accept)
        {
            using (var context = CreateContext())
            {
                try
                {
                    // Get carpool confirmation
                    CarpoolConfirmation carpoolConfirmation = await context.CarpoolConfirmations
                                                              .Include(x => x.CarpoolEvent)
                                                              .FirstOrDefaultAsync(x => x.Id == carpoolConfirmationId);

                    int passengerId = carpoolConfirmation.PassengerId;
                    int driverId    = carpoolConfirmation.CarpoolEvent.DriverId;
                    // User has answered a confirmation that was not for them
                    if (userId != passengerId && userId != driverId)
                    {
                        return(new DataResponse(500, Resources.AppResources.could_not_answer_confirmation));
                    }
                    // It is passenger or driver
                    bool isDriver = userId == driverId;
                    // Has accepted
                    if (accept)
                    {
                        // Set flags
                        carpoolConfirmation.HasDriverAccepted    = isDriver;
                        carpoolConfirmation.HasPassengerAccepted = !isDriver;
                    }
                    // Has denied
                    else
                    {
                        // Remove carpool confirmation
                        context.Remove(carpoolConfirmation);
                    }
                    // Save changes
                    int rowsChanged = await context.SaveChangesAsync();

                    // Error when saving
                    if (rowsChanged != 1)
                    {
                        return(new DataResponse(500, Resources.AppResources.could_not_answer_confirmation));
                    }
                    // Return response
                    return(new DataResponse(true));
                }
                catch (Exception mes)
                {
                    // Return exception
                    return(new DataResponse(1, mes.Message));
                }
            }
        }
Esempio n. 3
0
        public async Task <DataResponse> InvitePassenger(int carpoolRequestId, int carpoolEventId)
        {
            using (var context = CreateContext())
            {
                try
                {
                    // Get carpool request
                    CarpoolRequest carpoolRequest = await context.CarpoolRequests.FirstOrDefaultAsync(x => x.Id == carpoolRequestId);

                    // Set carpool request to inactive
                    carpoolRequest.StateId = 2;
                    // Create carpool confirmation
                    CarpoolConfirmation carpoolConfirmation = new CarpoolConfirmation()
                    {
                        CarpoolEventId       = carpoolEventId,
                        HasDriverAccepted    = true,
                        HasPassengerAccepted = false,
                        StateId     = 1,
                        PassengerId = carpoolRequest.PassengerId
                    };
                    // Add new carpool confirmation
                    await context.CarpoolConfirmations.AddAsync(carpoolConfirmation);

                    // Save changes
                    int rowsChanged = await context.SaveChangesAsync();

                    // Error when saving
                    if (rowsChanged < 1)
                    {
                        return(new DataResponse(401, Resources.AppResources.could_not_invite_passenger));
                    }
                    // Return response
                    return(new DataResponse(true));
                }
                catch (Exception mes)
                {
                    // Return exception
                    return(new DataResponse(1, mes.Message));
                }
            }
        }
Esempio n. 4
0
        public async Task <DataResponse> SignUpToCarpoolEvent(int carpoolEventId, int userId)
        {
            using (var context = CreateContext())
            {
                try
                {
                    // Create carpool confirmation
                    CarpoolConfirmation carpoolConfirmation = new CarpoolConfirmation()
                    {
                        CarpoolEventId       = carpoolEventId,
                        HasDriverAccepted    = false,
                        HasPassengerAccepted = true,
                        StateId     = 1,
                        PassengerId = userId
                    };
                    // Add new carpool confirmation
                    await context.CarpoolConfirmations.AddAsync(carpoolConfirmation);

                    // Save changes
                    int rowsChanged = await context.SaveChangesAsync();

                    // Error when saving
                    if (rowsChanged != 1)
                    {
                        return(new DataResponse(402, Resources.AppResources.could_not_sign_up_to_carpool));
                    }
                    // Return response
                    return(new DataResponse(true));
                }
                catch (Exception mes)
                {
                    // Return exception
                    return(new DataResponse(1, mes.Message));
                }
            }
        }