public MoviesViewModel Handle(GetMoviesById message) { try { string validateModel = message == null ? "Command model is null, bad request" : message.ValidateModel(); if (string.IsNullOrEmpty(validateModel)) { var ServiceCommand = new ServiceCommand(); var Movie = ServiceCommand.CreateMovies(message.Id, message.Title, (int)message.RunningTime, message.ReleaseDate, (bool)message.IsDeleted, message.Rating, message.Discription, (int)message.BookingId); ServiceCommand.SaveChanges(); return(new MoviesViewModel { Id = message.Id, Title = message.Title, RunningTime = message.RunningTime, ReleaseDate = message.ReleaseDate, IsDeleted = message.IsDeleted, Rating = message.Rating, Discription = message.Discription, BookingId = message.BookingId }); } throw new System.Exception(validateModel); } catch (System.Exception exc) { throw exc; } }
public MoviesViewModel Handle(UpdateMoviesCommand message) { try { string validateModel = message == null ? "Command model is null, bad request" : message.ValidateModel(); if (string.IsNullOrEmpty(validateModel)) { var commandService = new ServiceCommand(); var movies = commandService.UpdateMovies(message.Id, message.Title, (int)message.RunningTime, message.ReleaseDate, (bool)message.IsDeleted, message.Rating, message.Discription, (int)message.BookingId); commandService.SaveChanges(); return(new MoviesViewModel { Id = movies.Id, Title = movies.Title, RunningTime = (int)movies.RunningTime, ReleaseDate = (System.DateTime)movies.ReleaseDate, IsDeleted = (bool)movies.IsDeleted, Rating = movies.Rating, Discription = movies.Discription, BookingId = movies.BookingId }); } throw new System.Exception(validateModel); } catch (System.Exception exc) { var log = new ExceptionLog().Log(exc, message); throw exc; } }
// public DeleteMoviesCommand() public bool Handle(DeleteMoviesCommand message) { try { string validateModel = message == null ? "Command model is null, bad request" : message.ValidateModel(); if (string.IsNullOrEmpty(validateModel)) { var commandService = new ServiceCommand(); commandService.DeleteMovies(message.Id); commandService.SaveChanges(); return(true); } throw new System.Exception(validateModel); } catch (System.Exception exc) { var log = new ExceptionLog().Log(exc, message); throw exc; } }