public async Task <KerykeionDbResult> UpdateAsync(Image image, IFormFile file, IEnumerable <KeyValuePair <string, StringValues> > formForeignKeys) { if (image == null || file == null) { return(KerykeionDbResult.Fail(new KerykeionDbError { Message = "The supplied arguments are not valid." })); } if (formForeignKeys != null) { var result = await EntitiesService.SetForeignKeysAsync(image, formForeignKeys); if (!result.Successfull) { return(result); } } var replaceImgResult = await _imagesService.ReplaceImage(image?.Url.Split("/").Last(), file); if (replaceImgResult.Success) { image.Url = $"/images/{replaceImgResult.ImgUrl}"; return(await UpdateAsync(image)); } return(KerykeionDbResult.Fail(new KerykeionDbError { Message = "Could not upload the new image." })); }
private KerykeionDbResult KerykeionDbResultAfterTryCreateUser(IdentityResult result, TUser user) { if (result.Succeeded) { return(KerykeionDbResult.Success(user)); } return(KerykeionDbResultFilledWithErrors(result.Errors)); }
public async Task <KerykeionDbResult> AddLoginAsync(dynamic user, ExternalLoginInfo info) { IdentityResult result = await UserManager.AddLoginAsync(user, info); if (result.Succeeded) { return(KerykeionDbResult.Success(user)); } return(KerykeionDbResultFilledWithErrors(result.Errors)); }
private KerykeionDbResult KerykeionDbResultFilledWithErrors(IEnumerable <IdentityError> identityErrors) { var errors = new List <KerykeionDbError>(); foreach (var error in identityErrors) { errors.Add(new KerykeionDbError { Message = error.Description }); } return(KerykeionDbResult.Fail(errors.ToArray())); }
public async Task <KerykeionDbResult> CreateAsync(string username, string email) { var user = ActivateUser(username, email); if (user == null) { return(KerykeionDbResult.Fail()); } var result = await UserManager.CreateAsync(user); return(KerykeionDbResultAfterTryCreateUser(result, user)); }
public async Task <KerykeionDbResult> SetLanguageAsync(dynamic user, string language) { KerykeionUser thisUser = await UserManager.FindByIdAsync(user.Id.ToString()); if (thisUser != null) { user.Language = Enum.Parse <KerykeionCmsLanguage>(language); IdentityResult result = await UserManager.UpdateAsync(user); if (result.Succeeded) { return(KerykeionDbResult.Success()); } } return(KerykeionDbResult.Fail()); }
public async Task <KerykeionDbResult> CreateAsync(string username, string email, string password, IFormFile file, string language) { var user = ActivateUser(username, email); if (user == null) { return(KerykeionDbResult.Fail()); } if (file == null && _options.User.RequireProfileImage) { return(KerykeionDbResult.Fail(new KerykeionDbError { Message = "Een profiel foto is verplicht." })); } if (file != null) { if (!await AddProfileImageToUserAndCheckCompletion(file, user)) { return(KerykeionDbResult.Fail(new KerykeionDbError { Message = "Het uploaden van de profiel foto is mislukt." })); } } if (string.IsNullOrEmpty(language)) { user.Language = _options.Pages.Language; } else { if (Enum.TryParse <KerykeionCmsLanguage>(language, out _)) { user.Language = Enum.Parse <KerykeionCmsLanguage>(language); } else { user.Language = _options.Pages.Language; } } var result = await UserManager.CreateAsync(user, password); return(KerykeionDbResultAfterTryCreateUser(result, user)); }
public async Task <KerykeionDbResult> AddLinkAsync(Webpage page, Link link) { if (page == null || link == null) { return(KerykeionDbResult.Fail()); } var p = await FindByIdAllIncludedAsync(page.Id); if (p == null) { return(KerykeionDbResult.Fail(new KerykeionDbError { Message = "The page to add articles returned null!" })); } p.Links.Add(link); return(await UpdateAsync(p)); }
public async Task <KerykeionDbResult> RemoveImageAndDeleteAsync(Image image) { if (image == null) { return(KerykeionDbResult.Fail(new KerykeionDbError { Message = "The supplied arguments are not valid." })); } var removeImgResult = await _imagesService.DeleteImage(image.Url.Split("/").Last()); if (removeImgResult.Success) { return(await DeleteAsync(image)); } return(KerykeionDbResult.Fail(new KerykeionDbError { Message = "Could not delete the image." })); }
public async Task <KerykeionDbResult> AddProfileImage(dynamic user, IFormFile profileImage) { if (!(await GetUserProfileImageIncluded(user) is TUser currentUser)) { return(KerykeionDbResult.Fail()); } var errors = new List <KerykeionDbError>(); if (currentUser.ProfileImage != null) { //var delImgResult = await EntitiesService.DeleteAsync(currentUser.ProfileImage, FolderConstants.UserProfileImagesFolderName); //if (!delImgResult.Successfull) //{ // return delImgResult; //} } if (await AddProfileImageToUserAndCheckCompletion(profileImage, currentUser)) { var updateUserResult = await UserManager.UpdateAsync(currentUser); if (updateUserResult.Succeeded) { return(KerykeionDbResult.Success()); } foreach (var error in updateUserResult.Errors) { errors.Add(new KerykeionDbError { Message = error.Description }); } } errors.Add(new KerykeionDbError { Message = "Het uploaden van de afbeelding is mislukt." }); return(KerykeionDbResult.Fail(errors.ToArray())); }
public async Task <KerykeionDbResult> CreateAsync(Image image, IFormFile file, IEnumerable <KeyValuePair <string, StringValues> > formForeignKeys) { if (image == null || file == null) { return(KerykeionDbResult.Fail(new KerykeionDbError { Message = "The supplied arguments are not valid." })); } if (string.IsNullOrEmpty(image.Name)) { return(KerykeionDbResult.Fail(new KerykeionDbError { Message = "Please provide a name for the Image." })); } if (formForeignKeys != null) { var result = await EntitiesService.SetForeignKeysAsync(image, formForeignKeys); if (!result.Successfull) { return(result); } } var uploadResult = await _imagesService.SaveImage(file); if (uploadResult.Success) { image.Url = $"/images/{uploadResult.ImgUrl}"; return(await CreateAsync(image)); } return(KerykeionDbResult.Fail(new KerykeionDbError { Message = "The upload of the file failed." })); }