public async Task <ResponseDto <BaseModelDto> > AddSeason(int tvSeriesId, AddSeasonBindingModel seasonBindingModel) { var response = new ResponseDto <BaseModelDto>(); var tvSeriesExists = await _tvShowRepository.ExistAsync(x => x.Id == tvSeriesId); if (!tvSeriesExists) { response.AddError(Model.TvShow, Error.tvShow_NotFound); return(response); } var seasonExists = await _seasonRepository.GetByAsync(x => x.SeasonNumber == seasonBindingModel.SeasonNumber && x.TvShowId == tvSeriesId); if (seasonExists != null) { response.AddError(Model.Season, Error.season_Exists); return(response); } var season = _mapper.Map <Season>(seasonBindingModel); season.TvShowId = tvSeriesId; var result = await _seasonRepository.AddAsync(season); if (!result) { response.AddError(Model.Season, Error.season_Adding); return(response); } return(response); }
public async Task <ResponseDto <BaseModelDto> > DeleteCategoryAssignment(int categoryAssignmentId) { var response = new ResponseDto <BaseModelDto>(); var categoryAssignmentExists = await _tvShowCategoryAssignemtsRepository.ExistAsync(x => x.Id == categoryAssignmentId); if (!categoryAssignmentExists) { response.AddError(Model.CategoryAssignment, Error.categoryAssignment_NotFound); return(response); } var categoryAssignment = await _tvShowCategoryAssignemtsRepository.GetByAsync(x => x.Id == categoryAssignmentId); var result = await _tvShowCategoryAssignemtsRepository.Remove(categoryAssignment); if (!result) { response.AddError(Model.CategoryAssignment, Error.categoryAssignment_Deleting); return(response); } return(response); }
public async Task <ResponseDto <BaseModelDto> > AddEpisode(int seasonId, AddEpisodeBindingModel episodeBindingModel) { var response = new ResponseDto <BaseModelDto>(); var seasonExists = await _seasonRepository.ExistAsync(x => x.Id == seasonId); if (!seasonExists) { response.AddError(Model.Season, Error.season_NotFound); return(response); } var episodeInDb = await _episodeRepository.GetByAsync(x => x.EpisodeNumber == episodeBindingModel.EpisodeNumber && x.SeasonId == seasonId); if (episodeInDb != null) { response.AddError(Model.Episode, Error.episode_Exists); return(response); } var episode = _mapper.Map <Episode>(episodeBindingModel); episode.SeasonId = seasonId; var result = await _episodeRepository.AddAsync(episode); if (!result) { response.AddError(Model.Episode, Error.episode_Adding); return(response); } return(response); }
public static ResponseDto <string> ValidateAddDocument(Case caseFromDb, IFormFile document, ClaimsPrincipal user) { var result = new ResponseDto <string>(); if (document.Length <= 0) { result.AddError(DocumentErrors.EmptyFile); return(result); } if (_allowedExtensions.All(x => x != Path.GetExtension(document.FileName))) { result.AddError(DocumentErrors.WrongExtension); return(result); } if (caseFromDb == null) { result.AddError(CaseErrors.NotFoundById); return(result); } if (user.Identity.Name != caseFromDb.Sender.Login) { result.AddError(UserErrors.NotAllowed); } return(result); }
public async Task <ResponseDto <BaseModelDto> > DeleteActor(int actorId) { var response = new ResponseDto <BaseModelDto>(); var actorExists = await _actorRepository.ExistAsync(x => x.Id == actorId); if (!actorExists) { response.AddError(Model.Actor, Error.actor_NotExists); return(response); } var actor = await _actorRepository.GetByAsync(x => x.Id == actorId); var result = await _actorRepository.Remove(actor); if (!result) { response.AddError(Model.Actor, Error.actor_Deleting); return(response); } if (File.Exists("wwwroot\\ActorsPictures\\" + actor.Photo)) { File.Delete("wwwroot\\ActorsPictures\\" + actor.Photo); } return(response); }
public async Task <ResponseDto <BaseModelDto> > DeleteNotification(int notificationId) { var response = new ResponseDto <BaseModelDto>(); var notificationExists = await _notificationRepository.ExistAsync(x => x.Id == notificationId); if (!notificationExists) { response.AddError(Model.Notification, Error.notification_NotFound); return(response); } var notification = await _notificationRepository.GetByAsync(x => x.Id == notificationId); if (notification != null) { var result = await _notificationRepository.Remove(notification); if (!result) { response.AddError(Model.Notification, Error.notification_Deleting); return(response); } } return(response); }
public async Task <ResponseDto <BaseModelDto> > DeleteTvSeriesUserRating(int ratingId) { var response = new ResponseDto <BaseModelDto>(); var ratingExists = await _tvSeriesUserRatingRepository.ExistAsync(x => x.Id == ratingId); if (!ratingExists) { response.AddError(Model.Rating, Error.rating_NotFound); return(response); } var rating = await _tvSeriesUserRatingRepository.GetByAsync(x => x.Id == ratingId); var result = await _tvSeriesUserRatingRepository.Remove(rating); if (!result) { response.AddError(Model.Rating, Error.rating_Deleting); return(response); } response = await AddTvSeriesRating(rating, response); return(response); }
public async Task <ResponseDto <GetTvSeriesRatingDto> > GetTvSeriesRatingForUser(string loggedUser, int tvSeriesId) { var response = new ResponseDto <GetTvSeriesRatingDto>(); var tvSeriesExists = await _tvSeriesRepository.ExistAsync(x => x.Id == tvSeriesId); if (!tvSeriesExists) { response.AddError(Model.TvShow, Error.tvShow_NotFound); return(response); } var rating = await _tvSeriesUserRatingRepository.GetByAsync(x => x.UserId == loggedUser && x.TvShowId == tvSeriesId); if (rating == null) { response.AddError(Model.Rating, Error.rating_Not_Added); return(response); } var mappedRating = _mapper.Map <GetTvSeriesRatingDto>(rating); response.DtoObject = mappedRating; return(response); }
protected ResponseDto <BaseModelDto> ModelStateErrors(ActionExecutingContext filterContext) { Type errors = typeof(Error); var response = new ResponseDto <BaseModelDto>(); var fieldsInErrors = typeof(Error).GetFields(); List <string> fieldNamesInErrors = new List <string>(); foreach (var field in fieldsInErrors) { fieldNamesInErrors.Add(field.GetValue(null).ToString()); } foreach (var key in filterContext.ModelState.Keys) { var value = filterContext.ModelState[key]; foreach (var error in value.Errors) { if (fieldNamesInErrors.Contains(error.ErrorMessage)) { response.AddError(key, error.ErrorMessage); } else { response.AddError(key, Error.data_Invalid); } } } return(response); }
public async Task <ResponseDto <BaseModelDto> > UpdateEpisode(int episodeId, UpdateEpisodeBindingModel episodeBindingModel) { var response = new ResponseDto <BaseModelDto>(); var episodeExists = await _episodeRepository.ExistAsync(x => x.Id == episodeId); if (!episodeExists) { response.AddError(Model.Episode, Error.episode_NotFound); return(response); } var episode = _mapper.Map <Episode>(episodeBindingModel); episode.Id = episodeId; var result = await _episodeRepository.UpdateAsync(episode); if (!result) { response.AddError(Model.Episode, Error.episode_Updating); return(response); } return(response); }
public async Task <ResponseDto <BaseModelDto> > AddNotification( AddNotificationBindingModel addNotificationBindingModel, int tvSeriesId, string userId) { var response = new ResponseDto <BaseModelDto>(); var tvSeriesExists = await _tvSeriesRepository.ExistAsync(x => x.Id == tvSeriesId); if (!tvSeriesExists) { response.AddError(Model.TvShow, Error.tvShow_NotFound); return(response); } if (userId == null) { response.AddError(Model.Account, Error.account_Login); return(response); } Notification notification = new Notification(); notification.CreateDateTime = DateTime.Now; notification.TvShowId = tvSeriesId; notification.UserId = userId; notification.Type = addNotificationBindingModel.Type; if (addNotificationBindingModel.Type == "watchedEpisode") { notification.FirstPart = "Dodano odcinek " + addNotificationBindingModel.EpisodeNumber + " serialu "; notification.SecondPart = " do obejrzanych"; } else if (addNotificationBindingModel.Type == "ratedTvSeries") { notification.FirstPart = "Oceniono serial "; notification.SecondPart = ""; } else if (addNotificationBindingModel.Type == "favouriteTvSeries") { notification.FirstPart = "Dodano serial "; notification.SecondPart = " do ulubionych"; } else if (addNotificationBindingModel.Type == "commentedTvSeries") { notification.FirstPart = "Dodano komentarz do serialu "; notification.SecondPart = ""; } var result = await _notificationRepository.AddAsync(notification); if (!result) { response.AddError(Model.Notification, Error.notification_Adding); return(response); } return(response); }
private async Task <ResponseDto <BaseModelDto> > AddTvSeriesRating(TvSeriesUserRating rating, ResponseDto <BaseModelDto> response) { var tvSeriesUserRatings = _tvSeriesUserRatingRepository.GetAllBy(x => x.TvShowId == rating.TvShowId); TvSeriesRatings ratings = new TvSeriesRatings(); foreach (var tvSeriesUserRating in tvSeriesUserRatings) { ratings.Effects += tvSeriesUserRating.Effects; ratings.Music += tvSeriesUserRating.Music; ratings.Story += tvSeriesUserRating.Average; ratings.Average += tvSeriesUserRating.Average; } ratings.Effects = ratings.Effects / tvSeriesUserRatings.Count(); ratings.Music = ratings.Music / tvSeriesUserRatings.Count(); ratings.Story = ratings.Story / tvSeriesUserRatings.Count(); ratings.Average = ratings.Average / tvSeriesUserRatings.Count(); ratings.TvShowId = rating.TvShowId; var tvSeriesRatingExists = await _tvSeriesRatingsRepository.ExistAsync(x => x.TvShowId == rating.TvShowId); if (tvSeriesRatingExists) { var tvSeriesRatings = await _tvSeriesRatingsRepository.GetByAsync(x => x.TvShowId == rating.TvShowId); tvSeriesRatings.Average = ratings.Average; tvSeriesRatings.Effects = ratings.Effects; tvSeriesRatings.Music = ratings.Music; tvSeriesRatings.Story = ratings.Story; var updateResult = await _tvSeriesRatingsRepository.UpdateAsync(tvSeriesRatings); if (!updateResult) { response.AddError(Model.Rating, Error.rating_Updating); return(response); } } else { var addingResult = await _tvSeriesRatingsRepository.AddAsync(ratings); if (!addingResult) { response.AddError(Model.Rating, Error.rating_Adding); return(response); } } return(response); }
public async Task <ResponseDto <BaseModelDto> > AddTvSeriesUserRating(string userLogged, int tvSeriesId, AddTvSeriesRatingBindingModel tvSeriesRatingBindingModel) { var response = new ResponseDto <BaseModelDto>(); var tvSeriesExists = await _tvSeriesRepository.ExistAsync(x => x.Id == tvSeriesId); if (!tvSeriesExists) { response.AddError(Model.TvShow, Error.tvShow_NotFound); return(response); } var ratingExists = await _tvSeriesUserRatingRepository.ExistAsync(x => x.UserId == userLogged && x.TvShowId == tvSeriesId); if (ratingExists) { response.AddError(Model.Rating, Error.rating_Already_Added); return(response); } var userRating = _mapper.Map <TvSeriesUserRating>(tvSeriesRatingBindingModel); userRating.Average = (userRating.Effects + userRating.Music + userRating.Story) / 3; userRating.TvShowId = tvSeriesId; userRating.UserId = userLogged; var result = await _tvSeriesUserRatingRepository.AddAsync(userRating); if (!result) { response.AddError(Model.Rating, Error.rating_Adding); return(response); } else { if (userLogged != null) { AddNotificationBindingModel addNotificationBindingModel = new AddNotificationBindingModel(); addNotificationBindingModel.Type = "ratedTvSeries"; await _notificationService.AddNotification(addNotificationBindingModel, tvSeriesId, userLogged); } } response = await AddTvSeriesRating(userRating, response); return(response); }
public static ResponseDto <int> ValidateUpdateUser(ClaimsPrincipal loggedInUser, AddUserDto userToUpdate, User userFromDb) { var response = new ResponseDto <int>(); if (userFromDb == null) { response.AddError(UserErrors.NotFoundByLogin); } if (!loggedInUser.IsInRole(Role.SuperAdmin)) { response.AddError(UserErrors.NotAllowed); } return(response); }
public async Task <ResponseDto <BaseModelDto> > UpdateAvatar(IFormFile avatar, string userId) { var response = new ResponseDto <BaseModelDto>(); var user = await _userManager.FindByIdAsync(userId); if (user == null) { response.AddError(Model.Account, Error.account_UserNotFound); return(response); } else { if (user.Avatar != "") { if (File.Exists(("wwwroot\\UsersPictures\\" + user.Avatar))) { File.Delete("wwwroot\\UsersPictures\\" + user.Avatar); } } if (!Directory.Exists("wwwroot\\UsersPictures")) { Directory.CreateDirectory("wwwroot\\UsersPictures"); } var fileName = Guid.NewGuid() + Path.GetExtension(avatar.FileName); var filePath = Path.Combine("wwwroot\\UsersPictures", fileName); using (var stream = new FileStream(filePath, FileMode.Create)) { await avatar.CopyToAsync(stream); } user.Avatar = fileName; var result = await _userManager.UpdateAsync(user); if (result.Errors.Any()) { foreach (var error in result.Errors) { response.AddError(Model.Account, error.Description); } return(response); } } return(response); }
public async Task <ResponseDto <BaseModelDto> > AddCategoryAssignment(int categoryId, int tvShowId) { var response = new ResponseDto <BaseModelDto>(); var categoryExists = await _categoryRepository.ExistAsync(x => x.Id == categoryId); if (!categoryExists) { response.AddError(Model.Category, Error.category_NotFound); return(response); } var tvShowExists = await _tvShowRepository.ExistAsync(x => x.Id == tvShowId); if (!tvShowExists) { response.AddError(Model.TvShow, Error.tvShow_NotFound); return(response); } var tvShow = await _tvShowRepository.GetByAsync(x => x.Id == tvShowId); var category = await _categoryRepository.GetByAsync(x => x.Id == categoryId); var categoryAssignmentExists = await _tvShowCategoryAssignemtsRepository.ExistAsync(x => x.Category == category && x.TvShow == tvShow); if (categoryAssignmentExists) { response.AddError(Model.CategoryAssignment, Error.categoryAssignment_Already_Exists); return(response); } var categoryAssignment = new TvShowCategoryAssignments(); categoryAssignment.TvShow = tvShow; categoryAssignment.Category = category; var result = await _tvShowCategoryAssignemtsRepository.AddAsync(categoryAssignment); if (!result) { response.AddError(Model.CategoryAssignment, Error.categoryAssignment_Adding); return(response); } return(response); }
public async Task <ResponseDto <BaseModelDto> > AssignActorToTvShow(int actorId, int tvShowId, string characterName) { var response = new ResponseDto <BaseModelDto>(); var actorExists = await _actorRepository.ExistAsync(x => x.Id == actorId); if (!actorExists) { response.AddError(Model.Actor, Error.actor_NotExists); return(response); } var tvShowExists = await _tvShowRepository.ExistAsync(x => x.Id == tvShowId); if (!tvShowExists) { response.AddError(Model.TvShow, Error.tvShow_NotFound); return(response); } var tvShow = await _tvShowRepository.GetByAsync(x => x.Id == tvShowId); var actor = await _actorRepository.GetByAsync(x => x.Id == actorId); var assingmentExists = await _actorsAssignmentsRepository.ExistAsync(x => x.Actor == actor && x.TvShow == tvShow); if (assingmentExists) { response.AddError(Model.Actor, Error.actor_Assignment_Exists); return(response); } var assingment = new ActorsAssignments(); assingment.Actor = actor; assingment.TvShow = tvShow; assingment.CharacterName = characterName; var result = await _actorsAssignmentsRepository.AddAsync(assingment); if (!result) { response.AddError(Model.Assignment, Error.assignment_Adding); return(response); } return(response); }
public async Task <ResponseDto <GetLoggedUserDto> > Login(LoginBindingModel model) { var response = new ResponseDto <GetLoggedUserDto>(); var user = await _userManager.FindByNameAsync(model.Login); if (user == null) { user = await _userManager.FindByEmailAsync(model.Login); } var checkPassword = await _userManager.CheckPasswordAsync(user, model.Password); if (user != null && checkPassword) { var identity = new ClaimsIdentity("Identity.Application"); identity.AddClaim(new Claim(ClaimTypes.Name, user.Id)); identity.AddClaim(new Claim(ClaimTypes.Email, user.Email)); await _httpContext.HttpContext.SignInAsync("Identity.Application", new ClaimsPrincipal(identity), new AuthenticationProperties { IsPersistent = true }); var userFromDb = await _userManager.FindByNameAsync(user.Id); var mappedUser = _mapper.Map <GetLoggedUserDto>(userFromDb); response.DtoObject = mappedUser; return(response); } response.AddError(Model.Account, Error.account_WrongCredentials); return(response); }
public static ResponseDto <int> ValidateAddDepartment(Department department, AddDepartmentDto departmentDto) { var response = new ResponseDto <int>(); if (department != null) { response.AddError(DepartmentErrors.NameExists); } if (departmentDto.Name.Length < 2) { response.AddError(DepartmentErrors.TooShortName); } return(response); }
public async Task <ResponseDto <BaseModelDto> > AddSeasonToWatched(int seasonId, string userId) { var response = new ResponseDto <BaseModelDto>(); var watchedEpisodes = _episodeRepository.GetAllBy(x => x.SeasonId == seasonId); List <UserWatchedEpisode> userWatchedEpisodesList = new List <UserWatchedEpisode>(); foreach (var episode in watchedEpisodes) { UserWatchedEpisode watchedEpisode = new UserWatchedEpisode(); watchedEpisode.EpisodeId = episode.Id; watchedEpisode.UserId = userId; if (await _userWatchedEpisodeRepository.ExistAsync(x => x.EpisodeId == episode.Id && x.UserId == userId) == false) { userWatchedEpisodesList.Add(watchedEpisode); } } foreach (var episode in userWatchedEpisodesList) { var result = await _userWatchedEpisodeRepository.AddAsync(episode); if (!result) { response.AddError(Model.Episode, Error.watchedTvShow_Adding); return(response); } } return(response); }
public static ResponseDto <bool> ValidateAssignManager(Department departmentFromDb, User userFromDb) { var response = new ResponseDto <bool>(); if (departmentFromDb == null) { response.AddError(DepartmentErrors.NotFoundById); } if (userFromDb == null) { response.AddError(UserErrors.NotFoundById); } return(response); }
public static ResponseDto <int> ValidateAddDocumentType(Department departmentFromDb, AddDocumentTypeDto documentTypeToAdd) { ResponseDto <int> response = new ResponseDto <int>(); if (departmentFromDb == null) { response.AddError(DepartmentErrors.NotFoundById); } if (string.IsNullOrEmpty(documentTypeToAdd.Name)) { response.AddError(DocumentTypeErrors.EmptyName); } return(response); }
public async Task <ResponseDto <EpisodeDto> > GetClosestEpisode(int tvSeriesId) { var response = new ResponseDto <EpisodeDto>(); var tvSeriesExists = await _tvSeriesRepository.ExistAsync(x => x.Id == tvSeriesId); if (!tvSeriesExists) { response.AddError(Model.TvShow, Error.tvShow_NotFound); return(response); } DateTime localDate = DateTime.Now; var episodes = _episodeRepository.GetAllBy(x => x.Season.TvShow.Id == tvSeriesId && x.AiringDate >= localDate); Episode episode = new Episode(); if (episodes.Any()) { episode = episodes.OrderBy(x => x.AiringDate).First(); response.DtoObject = _mapper.Map <EpisodeDto>(episode); } return(response); }
public async Task <ResponseDto <BaseModelDto> > AddActor(AddActorBindingModel addActorBindingModel) { var response = new ResponseDto <BaseModelDto>(); if (!Directory.Exists("wwwroot\\ActorsPictures")) { Directory.CreateDirectory("wwwroot\\ActorsPictures"); } var fileName = Guid.NewGuid() + Path.GetExtension(addActorBindingModel.Photo.FileName); var filePath = Path.Combine("wwwroot\\ActorsPictures", fileName); using (var stream = new FileStream(filePath, FileMode.Create)) { await addActorBindingModel.Photo.CopyToAsync(stream); } var actor = _mapper.Map <Actor>(addActorBindingModel); actor.Photo = fileName; var result = await _actorRepository.AddAsync(actor); if (!result) { File.Delete(filePath); response.AddError(Model.Actor, Error.actor_Adding); return(response); } return(response); }
public async Task <ResponseDto <GetTvSeriesRatingDto> > GetTvSeriesRating(int tvSeriesId) { var response = new ResponseDto <GetTvSeriesRatingDto>(); var tvSeriesExists = await _tvSeriesRepository.ExistAsync(x => x.Id == tvSeriesId); if (!tvSeriesExists) { response.AddError(Model.TvShow, Error.tvShow_NotFound); return(response); } var tvSeriesRatings = _tvSeriesUserRatingRepository.GetAllBy(x => x.TvShowId == tvSeriesId); GetTvSeriesRatingDto tmpRating = new GetTvSeriesRatingDto(); foreach (var tvSeriesRating in tvSeriesRatings) { tmpRating.Story += tvSeriesRating.Story; tmpRating.Music += tvSeriesRating.Music; tmpRating.Effects += tvSeriesRating.Effects; tmpRating.Average += tvSeriesRating.Average; } tmpRating.Story = tmpRating.Story / tvSeriesRatings.Count(); tmpRating.Music = tmpRating.Music / tvSeriesRatings.Count(); tmpRating.Effects = tmpRating.Effects / tvSeriesRatings.Count(); tmpRating.Average = tmpRating.Average / tvSeriesRatings.Count(); response.DtoObject = tmpRating; return(response); }
public async Task <ResponseDto <BaseModelDto> > AddTvShow(AddTvShowBindingModel tvShowBindingModel) { var response = new ResponseDto <BaseModelDto>(); if (!Directory.Exists("wwwroot\\TvShowsPictures")) { Directory.CreateDirectory("wwwroot\\TvShowsPictures"); } var fileName = Guid.NewGuid() + Path.GetExtension(tvShowBindingModel.Photo.FileName); var filePath = Path.Combine("wwwroot\\TvShowsPictures", fileName); var backgroundFileName = Guid.NewGuid() + Path.GetExtension(tvShowBindingModel.BackgroundPhoto.FileName); var backgroundFilePath = Path.Combine("wwwroot\\TvShowsPictures", backgroundFileName); using (var stream = new FileStream(filePath, FileMode.Create)) { await tvShowBindingModel.Photo.CopyToAsync(stream); } using (var stream = new FileStream(backgroundFilePath, FileMode.Create)) { await tvShowBindingModel.BackgroundPhoto.CopyToAsync(stream); } var tvShow = _mapper.Map <TvShow>(tvShowBindingModel); tvShow.PhotoName = fileName; tvShow.BackgroundPhotoName = backgroundFileName; var tvShowInDatabase = await _tvShowRepository.GetByAsync(x => x.Name.ToLower() == tvShowBindingModel.Name.ToLower()); if (tvShowInDatabase != null) { response.AddError(Model.TvShow, Error.tvShow_Exists); return(response); } var result = await _tvShowRepository.AddAsync(tvShow); if (!result) { response.AddError(Model.TvShow, Error.tvShow_Adding); } return(response); }
public async Task <ResponseDto <BaseModelDto> > AddComment(AddCommentBindingModel addCommentBindingModel, int tvSeriesId, string userId) { var response = new ResponseDto <BaseModelDto>(); var tvSeriesExists = await _tvSeriesRepository.ExistAsync(x => x.Id == tvSeriesId); if (!tvSeriesExists) { response.AddError(Model.TvShow, Error.tvShow_NotFound); return(response); } if (userId == null) { response.AddError(Model.Account, Error.account_Login); return(response); } Comment comment = new Comment(); comment.Content = addCommentBindingModel.Content; comment.TvSeriesId = tvSeriesId; comment.UserId = userId; comment.CreateDateTime = DateTime.Now; comment.UpdateDateTime = DateTime.Now; var result = await _commentRepository.AddAsync(comment); if (!result) { response.AddError(Model.Comment, Error.comment_Adding); return(response); } else { if (userId != null) { AddNotificationBindingModel addNotificationBindingModel = new AddNotificationBindingModel(); addNotificationBindingModel.Type = "commentedTvSeries"; await _notificationService.AddNotification(addNotificationBindingModel, tvSeriesId, userId); } } return(response); }
public async Task <ResponseDto <BaseModelDto> > AddUserFavouriteTvSeries(int episodeId, string userId) { var response = new ResponseDto <BaseModelDto>(); var episodeExists = await _episodeRepository.ExistAsync(x => x.Id == episodeId); if (!episodeExists) { response.AddError(Model.TvShow, Error.tvShow_NotFound); return(response); } var watchedTvSeriesInDb = await _userWatchedEpisodeRepository.GetByAsync(x => x.EpisodeId == episodeId && x.UserId == userId); if (watchedTvSeriesInDb != null) { response.AddError(Model.WatchedEpisode, Error.watchedEpisode_Already_Exists); return(response); } UserWatchedEpisode watchedEpisode = new UserWatchedEpisode(); watchedEpisode.CreateDateTime = DateTime.Now; watchedEpisode.EpisodeId = episodeId; watchedEpisode.UserId = userId; var result = await _userWatchedEpisodeRepository.AddAsync(watchedEpisode); if (!result) { response.AddError(Model.FavouriteTvShow, Error.favouriteTvShow_Adding); return(response); } else { AddNotificationBindingModel addNotificationBindingModel = new AddNotificationBindingModel(); addNotificationBindingModel.Type = "watchedEpisode"; var episode = await _episodeRepository.GetByAsync(x => x.Id == episodeId, x => x.Season.TvShow); addNotificationBindingModel.EpisodeNumber = episode.EpisodeNumber; await _notificationService.AddNotification(addNotificationBindingModel, episode.Season.TvShow.Id, userId); } return(response); }
public static ResponseDto <bool> ValidateDeleteUser(ClaimsPrincipal userIdentity, User userFromDb) { var response = new ResponseDto <bool>(); if (userFromDb == null || userFromDb.IsDeleted) { response.AddError(UserErrors.NotFoundById); return(response); } if (userIdentity.IsInRole("User") && userIdentity.Identity.Name != userFromDb.Login) { response.AddError(UserErrors.CannotDeleteUser); } return(response); }
public static ResponseDto <LoggedInUserDto> ValidateAuthenticate(User user, LoginUserDto loginUser) { var response = new ResponseDto <LoggedInUserDto>(); if (user == null) { response.AddError(UserErrors.NotFoundByLogin); return(response); } if (!user.Password.IsEqualTo(loginUser.Password.GenerateSaltedHash(user.Salt))) { response.AddError(UserErrors.InvalidPassword); } return(response); }