This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace PredictableCoding.Controllers.Entities | |
| { | |
| public class Movie { | |
| public string Title { get; set; } | |
| public string Description { get; set; } | |
| public Actor Actors { get; set; } | |
| private string _Genre; | |
| public string Genre { | |
| get => _Genre; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://github.com/ChuckkNorris/PredictableCoding/blob/master/Entities/Movie/Movie.cs | |
| public class Movie { | |
| public string Title { get; set; } | |
| public string Description { get; set; } | |
| public Actor Actors { get; set; } | |
| private string _Genre; | |
| public string Genre { | |
| get => _Genre; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class NullCoalescingOperator | |
| { | |
| // Write your code to be expectant of null values | |
| public IEnumerable<Movie> SearchMovies(string searchTerm) | |
| { | |
| IEnumerable<Movie> toReturn; | |
| string lowerSearchTerm = searchTerm.ToLower(); | |
| // Search Movies | |
| toReturn = this.Movies.Where(movie => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MovieService : IService | |
| { | |
| private UserService _userService; | |
| public MovieService(UserService userService) | |
| { | |
| this._userService = userService; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public IEnumerable<MovieDto> SearchMovies(string searchTerm) { | |
| IEnumerable<MovieDto> toReturn = new List<MovieDto>(); | |
| string lowerSearchTerm = searchTerm?.ToLower(); | |
| // Search Movies | |
| if (!String.IsNullOrEmpty(lowerSearchTerm)) | |
| { | |
| toReturn = this.Movies?.Where(movie => | |
| (movie?.Name?.ToLower().Contains(searchTerm) ?? false) | |
| || (movie?.Actors?.Any(actor => | |
| (actor?.FirstName?.ToLower().Contains(searchTerm) ?? false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public UserDto GetUser(string email) { | |
| if (string.IsNullOrEmpty(email)) throw new ArgumentException("message", nameof(email)); | |
| UserDto toReturn = null; | |
| toReturn = Users?.FirstOrDefault(user => user?.Email == email); | |
| return toReturn; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void ConfigureServices(IServiceCollection services) { | |
| services.AddMvc(); | |
| InjectServices(services); | |
| } | |
| private void InjectServices(IServiceCollection services) { | |
| // This will become very tedious later | |
| //services.AddTransient<UserService>(); | |
| //services.AddTransient<MovieService>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public UserDto GetUser(string email) { | |
| if (!ValidationUtil.IsValidEmail(email)) | |
| throw new ArgumentException("Must be a properly formatted email", nameof(email)); | |
| UserDto toReturn = null; | |
| toReturn = Users?.FirstOrDefault(user => user?.Email == email); | |
| return toReturn; | |
| } | |
| public bool AreCredentialsValid(string email, string password) { | |
| bool toReturn = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Middlware intercepts exceptions thrown during a request | |
| private static Task HandleExceptionAsync(HttpContext context, Exception exception) | |
| { | |
| var code = HttpStatusCode.InternalServerError; // 500 if unexpected | |
| string userErrorMessage = "Sorry, something went wrong"; | |
| if (exception is UserFriendlyException) { | |
| code = HttpStatusCode.BadRequest; | |
| userErrorMessage = exception.Message; | |
| } | |
| //else if (exception is MyUnauthorizedException) code = HttpStatusCode.Unauthorized; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ValidationUtil { | |
| public static bool IsValidEmail(string email) { | |
| bool toReturn = false; | |
| if (!String.IsNullOrEmpty(email)) { | |
| string emailPattern = @"^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*" | |
| + "@" | |
| + @"((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))$"; | |
| Regex reg = new Regex(emailPattern); | |
| toReturn = reg.IsMatch(email); | |
| } |
OlderNewer