Beispiel #1
0
        public async Task <CommandResult <Boolean> > UpdateTrip([FromBody] UpdateTripViewModel viewModel)
        {
            var updateModel = _mapper.Map <WebSiteTripModel>(viewModel);

            var result = await _tripManager.UpdateTrip(updateModel);

            if (result.IsSucceeded)
            {
                foreach (var image in viewModel.Images)
                {
                    this.ConfirmImageAdded(image);
                    this.ConfirmFileAdded(image);
                }
                if (!string.IsNullOrEmpty(viewModel.PdfName))
                {
                    this.ConfirmFileAdded(viewModel.PdfName);
                }
            }
            return(result);
        }
Beispiel #2
0
        public async Task <IHttpActionResult> Patch(string id, Delta <PatchTrip> userTrip)
        {
            var trip = GetTripForRole(id);

            if (trip == null)
            {
                return(NotFound());
            }
            var patchTrip = new PatchTrip(trip);

            userTrip.Patch(patchTrip);

            // Have to do manual validation here
            if (trip.StartDate > trip.EndDate)
            {
                ModelState.AddModelError("startDate", "Start date cannot be greater than end date");
            }
            if (string.IsNullOrEmpty(trip.Destination))
            {
                ModelState.AddModelError("destination", "Destination cannot be null or empty");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _tripManager.UpdateTrip(trip);

            return(Ok(new TripWithId
            {
                Id = trip.Id,
                StartDate = trip.StartDate,
                EndDate = trip.EndDate,
                Destination = trip.Destination,
                Comment = trip.Comment
            }));
        }