Beispiel #1
0
        public IHttpActionResult Put(int id, MoviePersonViewModel moviePerson)
        {
            var loggedUserId = HttpContext.Current.GetOwinContext().GetUserId();

            moviePerson.UserLastModified = new Models.Users.UserViewModel()
            {
                Id = loggedUserId
            };
            moviePerson.Lastmodified = DateTimeOffset.Now;


            if (ModelState.IsValid)
            {
                var request = new SaveMoviePersonRequest()
                {
                    RequestToken = Guid.NewGuid(),
                    UserId       = loggedUserId,
                    MoviePerson  = moviePerson.MapToView()
                };

                var moviePersonsResponse = _moviePersonService.SaveMoviePerson(request);

                if (!moviePersonsResponse.Success)
                {
                    return(BadRequest(moviePersonsResponse.Message));
                }

                return(Ok(moviePerson = moviePersonsResponse.MoviePerson.MapToViewModel()));
            }
            else
            {
                return(BadRequest());
            }
        }
 /// <summary>
 /// Maps Api.Models.MoviePersonViewModel into  Messaging.Views.MoviePerson
 /// </summary>
 /// <param name="viewModel">Api.Models.MoviePersonViewModel</param>
 /// <returns> Messaging.Views.MoviePerson</returns>
 public static MoviePerson MapToView(this MoviePersonViewModel viewModel)
 {
     if (viewModel == null)
     {
         return(null);
     }
     return(new MoviePerson()
     {
         Id = viewModel.Id,
         FirstName = viewModel.Firstname,
         LastName = viewModel.Lastname,
         FullName = viewModel.FullName,
         BirthPlace = viewModel.Birthplace,
         Biography = viewModel.Biography,
         PhotoUrl = viewModel.Photourl,
         Popularity = viewModel.Popularity,
         Birthday = viewModel.Birthday,
         DateCreated = viewModel.Datecreated,
         IMDBUrl = viewModel.IMDBUrl,
         UserLastModified = viewModel.UserLastModified.MapToView(),
         UserCreated = viewModel.UserCreated.MapToView()
     });
 }