示例#1
0
        public async Task <ActionResult> CreateAddOn([FromBody] AddOnCreateDTO newAddOn)
        {
            try
            {
                if (!await _editRightsService.HasEditRights(newAddOn.TripId))
                {
                    return(BadRequest(new JsonResult("You can't currently edit this trip.")));
                }
                AddOnDTO result = await _addOnService.CreateAddOn(newAddOn);

                await _editRightsService.ProlongEditRights(newAddOn.TripId, _redisAppSettings.EditRightsProlongedTTL);

                if (result != null)
                {
                    return(Ok(result));
                }
                return(BadRequest(new JsonResult("Invalid add on information")));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#2
0
        public async Task <ActionResult> EditTripInfo([FromBody] TripEditDTO tripInfo)
        {
            try
            {
                if (!await _editRightsService.HasEditRights(tripInfo.TripId))
                {
                    return(BadRequest(new JsonResult("You can't currently edit this trip.")));
                }
                TripDTO result = await _tripService.EditTripInfo(tripInfo);

                await _editRightsService.ProlongEditRights(tripInfo.TripId, _redisAppSettings.EditRightsProlongedTTL);

                if (result != null)
                {
                    return(Ok(result));
                }
                return(BadRequest(new JsonResult("Trip dates are not valid.")));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <ActionResult> Vote(int tripId, [FromBody] VoteCreateDTO newVote)
        {
            try
            {
                if (!await _editRightsService.HasEditRights(tripId))
                {
                    return(BadRequest(new JsonResult("You can't currently edit this trip.")));
                }
                VoteDTO retValue = await _voteService.Vote(newVote, tripId);

                await _editRightsService.ProlongEditRights(tripId, _redisAppSettings.EditRightsProlongedTTL);

                if (retValue == null)
                {
                    return(BadRequest(new JsonResult("You already voted for this item")));
                }
                return(Ok(retValue));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <ActionResult> CreateAccommodation(int tripId, [FromBody] AccommodationCreateDTO newAccommodation)
        {
            try
            {
                if (!await _editRightsService.HasEditRights(tripId))
                {
                    return(BadRequest(new JsonResult("You can't currently edit this trip.")));
                }
                AccommodationDTO result = await _accommodationService.CreateAccommodation(newAccommodation);

                await _editRightsService.ProlongEditRights(tripId, _redisAppSettings.EditRightsProlongedTTL);

                if (result != null)
                {
                    return(Ok(result));
                }
                return(BadRequest(new JsonResult("Accommodation dates are not valid.")));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#5
0
        public async Task <ActionResult> CreateItem([FromBody] ItemCreateDTO newItem)
        {
            try
            {
                if (!await _editRightsService.HasEditRights(newItem.TripId))
                {
                    return(BadRequest(new JsonResult("You can't currently edit this trip.")));
                }
                ItemDTO result = await _itemService.CreateItem(newItem);

                await _editRightsService.ProlongEditRights(newItem.TripId, _redisAppSettings.EditRightsProlongedTTL);

                if (result != null)
                {
                    return(Ok(result));
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }