public async Task <Profiledto> GetProfileByUserId(string userId) { if (userId is null) { throw new ArgumentNullException(nameof(userId)); } var profiles = await _repository.GetAll().AsNoTracking().ToListAsync(); var profileDataModel = profiles.FirstOrDefault(c => c.UserId.Equals(userId)); if (profileDataModel is null) { return(new Profiledto()); } var profile = new Profiledto { UserId = profileDataModel.UserId, FullName = profileDataModel.FullName, }; profile.Id = profileDataModel.Id; return(profile); }
public async Task AddAsync(Filmsdto film, Profiledto profile, int status) { if (film is null) { throw new ArgumentNullException(nameof(film)); } var getFilm = await _repository.GetEntityWithoutTrackingAsync(filmid => filmid.FilmsId == film.FilmsId); if (getFilm is null) { var filmmodel = new Films { FilmsName = film.FilmsName, FilmsId = film.FilmsId, // Year = film.Year, // Scenario = film.Scenario, // Producer = film.Producer, // Budget = film.Budget, // Premiere = film.Premiere, Duration = film.Duration, // Description = film.Description, Picture = film.Picture, // Rating = film.Rating, }; await _repository.AddAsync(filmmodel); await _repository.SaveChangesAsync(); } var getFilmmodel = await _repository.GetEntityWithoutTrackingAsync(filmid => filmid.FilmsId == film.FilmsId); var check = await _repositoryStatus.GetEntityAsync( checkString => checkString.ProfileId == profile.Id && checkString.FilmId == getFilmmodel.Id); if (check != null) { return; } var filmStatusModel = new Status { ProfileId = profile.Id, FilmId = getFilmmodel.Id, StatusName = status, }; await _repositoryStatus.AddAsync(filmStatusModel); await _repositoryStatus.SaveChangesAsync(); }
public async Task Edit(Profiledto profile) { if (profile is null) { throw new ArgumentNullException(nameof(profile)); } var editProfile = await _repository.GetEntityAsync(q => q.Id.Equals(profile.Id)); editProfile.FullName = profile.FullName; _repository.Update(editProfile); await _repository.SaveChangesAsync(); }
public async Task DeleteAsync(Filmsdto film, Profiledto profile) { var getFilmmodel = await _repository.GetEntityWithoutTrackingAsync(filmid => filmid.FilmsId == film.FilmsId); var delModel = await _repositoryStatus.GetEntityWithoutTrackingAsync(statusModel => statusModel.FilmId == getFilmmodel.Id && statusModel.ProfileId == profile.Id); if (delModel is null) { return; } _repositoryStatus.Delete(delModel); await _repositoryStatus.SaveChangesAsync(); }
public async Task AddAsync(Profiledto profile) { if (profile is null) { throw new ArgumentNullException(nameof(profile)); } var userProfile = new Profile { UserId = profile.UserId, FullName = profile.FullName, }; await _repository.AddAsync(userProfile); await _repository.SaveChangesAsync(); }
public async Task <IActionResult> EditProfile(ProfileViewModel editProfile) { var username = User.Identity.Name; var user = await _userManager.FindByNameAsync(username); var getProfile = await _profileService.GetProfileByUserId(user.Id); var profile = new Profiledto { Id = getProfile.Id, FullName = editProfile.FullName, }; await _profileService.Edit(profile); return(RedirectToAction("Profile")); }
public async Task <bool> CheckAddFilm(int id, Profiledto profile) { var getFilmmodel = await _repository.GetEntityWithoutTrackingAsync(filmid => filmid.FilmsId == id); if (getFilmmodel is null) { return(false); } var delModel = await _repositoryStatus.GetEntityWithoutTrackingAsync(statusModel => statusModel.FilmId == getFilmmodel.Id && statusModel.ProfileId == profile.Id); if (delModel is null) { return(false); } return(true); }
public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new User { Email = model.Email, UserName = model.Username }; // add user var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var profile = new Profiledto() { UserId = user.Id }; await _profileService.AddAsync(profile); // add cookies await _signInManager.SignInAsync(user, false); _emailService.Send(model.Email, "Hello", "Welcome to my site"); return(RedirectToAction("Index", "Home")); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } } return(View(model)); }