public async Task <bool> UpdateGroup(GroupInputModel model, int groupId, string userId) { var group = await this.groupRepository.All().FirstOrDefaultAsync(x => x.Id == groupId); if (group == null) { return(false); } group.Name = model.Name; group.Description = model.Description; if (model.CoverImage != null) { var imageName = Guid.NewGuid().ToString(); var imageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, model.CoverImage, imageName); if (!string.IsNullOrEmpty(imageUrl)) { group.CoverImage = new Image() { Url = imageUrl, Name = imageName, CreatorId = userId, }; } } this.groupRepository.Update(group); await this.groupRepository.SaveChangesAsync(); return(true); }
public async Task EditAsync(DestinationEditViewModel destinationEditViewModel) { var destination = this.destinationsRepository.All() .FirstOrDefault(d => d.Id == destinationEditViewModel.Id); if (destination == null) { throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceDestinationId, destinationEditViewModel.Id)); } var country = this.countriesRepository.All() .FirstOrDefault(c => c.Id == destinationEditViewModel.CountryId); if (country == null) { throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceCountryId, destinationEditViewModel.CountryId)); } if (destinationEditViewModel.NewImage != null) { var newImageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, destinationEditViewModel.NewImage, destinationEditViewModel.Name); destination.ImageUrl = newImageUrl; } destination.Name = destinationEditViewModel.Name; destination.Country = country; destination.Information = destinationEditViewModel.Information; this.destinationsRepository.Update(destination); await this.destinationsRepository.SaveChangesAsync(); }
public async Task <string> DeleteEmojisByType(EmojiType emojiType) { var targetEmojis = this.db.Emojis.Where(x => x.EmojiType == emojiType).ToList(); int count = 0; foreach (var emoji in targetEmojis) { var emojiSkins = this.db.EmojiSkins.Where(x => x.EmojiId == emoji.Id).ToList(); foreach (var emojiSkin in emojiSkins) { ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.EmojiSkin, emojiSkin.Id), GlobalConstants.EmojisFolder); } ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.EmojiName, emoji.Id), GlobalConstants.EmojisFolder); this.db.EmojiSkins.RemoveRange(emojiSkins); this.db.Emojis.Remove(emoji); this.db.SaveChanges(); await this.db.SaveChangesAsync(); count++; } return(string.Format( SuccessMessages.SuccessfullyDeletedEmojisByType, count, emojiType.ToString().ToUpper())); }
public async Task <bool> DeleteUserImagesByUsername(string username) { var user = this.db.Users.FirstOrDefault(x => x.UserName == username); if (user != null && (user.ImageUrl != null || user.CoverImageUrl != null)) { user.ImageUrl = null; ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.CloudinaryUserProfilePictureName, username), string.Format(GlobalConstants.UserProfilePicturesFolder, user.UserName)); user.CoverImageUrl = null; ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.CloudinaryUserCoverImageName, username), string.Format(GlobalConstants.UserProfilePicturesFolder, user.UserName)); this.db.Users.Update(user); await this.db.SaveChangesAsync(); return(true); } return(false); }
public async Task <Tuple <bool, string> > AddNewStickerType(AddChatStickerTypeInputModel model) { if (this.db.StickerTypes.Any(x => x.Name.ToUpper() == model.Name.ToUpper())) { return(Tuple.Create( false, string.Format(ErrorMessages.StickerTypeAlreadyExist, model.Name.ToUpper()))); } var stickerType = new StickerType { Name = model.Name, Position = await this.db.StickerTypes .Select(x => x.Position) .OrderByDescending(x => x) .FirstOrDefaultAsync() + 1, }; var imageUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, model.Image, string.Format(GlobalConstants.StickerTypeName, stickerType.Id), GlobalConstants.StickerTypeFolder); stickerType.Url = imageUrl; this.db.StickerTypes.Add(stickerType); await this.db.SaveChangesAsync(); return(Tuple.Create( true, string.Format(SuccessMessages.SuccessfullyAddedStickerType, stickerType.Name.ToUpper()))); }
public async Task <Tuple <bool, string> > EditStickerType(EditChatStickerTypeInputModel model) { if (this.db.StickerTypes.Any(x => x.Name.ToUpper() == model.Name.ToUpper())) { return(Tuple.Create(false, string.Format(ErrorMessages.StickerAlreadyTypeExist, model.Name.ToUpper()))); } var targetStickerType = await this.db.StickerTypes.FirstOrDefaultAsync(x => x.Id == model.Id); if (targetStickerType != null) { targetStickerType.Name = model.Name; if (model.Image != null) { var imageUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, model.Image, string.Format(GlobalConstants.StickerTypeName, model.Id), GlobalConstants.StickerTypeFolder); targetStickerType.Url = imageUrl; } this.db.StickerTypes.Update(targetStickerType); await this.db.SaveChangesAsync(); return(Tuple.Create( true, string.Format( SuccessMessages.SuccessfullyEditChatStickerType, targetStickerType.Name.ToUpper()))); } return(Tuple.Create(false, ErrorMessages.StickerTypeDoesNotExist)); }
public async Task <Tuple <bool, string> > DeleteHolidayTheme(string id) { var targetTheme = await this.db.HolidayThemes.FirstOrDefaultAsync(x => x.Id == id); if (targetTheme != null) { var themeName = targetTheme.Name; var allThemeIcons = this.db.HolidayIcons.Where(x => x.HolidayThemeId == targetTheme.Id).ToList(); foreach (var icon in allThemeIcons) { ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.HolidayIconName, icon.Id), GlobalConstants.HolidayThemesFolder); } this.db.HolidayIcons.RemoveRange(allThemeIcons); this.db.HolidayThemes.Remove(targetTheme); await this.db.SaveChangesAsync(); return(Tuple.Create( true, string.Format(SuccessMessages.SuccessfullyDeleteHolidayTheme, themeName.ToUpper()))); } return(Tuple.Create(false, ErrorMessages.HolidayThemeDoesNotExist)); }
public async Task <Tuple <bool, string> > AddEmoji(AddEmojiInputModel model) { if (this.db.Emojis.Any(x => x.Name.ToUpper() == model.Name.ToUpper() && x.EmojiType == model.EmojiType)) { return(Tuple.Create(false, string.Format(ErrorMessages.EmojiAlreadyExist, model.Name.ToUpper()))); } else { var lastNumber = await this.db.Emojis .Where(x => x.EmojiType == model.EmojiType) .Select(x => x.Position) .OrderByDescending(x => x) .FirstOrDefaultAsync(); var emoji = new Emoji { EmojiType = model.EmojiType, Name = model.Name, Position = lastNumber + 1, }; var imageUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, model.Image, string.Format(GlobalConstants.EmojiName, emoji.Id), GlobalConstants.EmojisFolder); emoji.Url = imageUrl; this.db.Emojis.Add(emoji); await this.db.SaveChangesAsync(); return(Tuple.Create(true, string.Format(SuccessMessages.SuccessfullyAddedEmoji, emoji.Name))); } }
public async Task <int> DeleteAllUsersImages() { int count = 0; var users = this.db.Users.Where(x => x.ImageUrl != null || x.CoverImageUrl != null).ToList(); foreach (var user in users) { if (user.ImageUrl != null) { user.ImageUrl = null; ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.CloudinaryUserProfilePictureName, user.UserName), string.Format(GlobalConstants.UserProfilePicturesFolder, user.UserName)); count++; } if (user.CoverImageUrl != null) { user.CoverImageUrl = null; ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.CloudinaryUserCoverImageName, user.UserName), string.Format(GlobalConstants.UserProfilePicturesFolder, user.UserName)); count++; } } this.db.Users.UpdateRange(users); await this.db.SaveChangesAsync(); return(count); }
public async Task CreateAsyncReturnsExistingViewModelIfRestaurantExists() { await this.AddTestingDestinationToDb(); await this.AddTestingCountryToDb(); DestinationDetailsViewModel destinationDetailsViewModel; using (var stream = File.OpenRead(TestImagePath)) { var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name)) { Headers = new HeaderDictionary(), ContentType = TestImageContentType, }; var destinationCreateInputModel = new DestinationCreateInputModel() { Name = TestDestinationName, CountryId = TestCountryId, Image = file, }; destinationDetailsViewModel = await this.DestinationsServiceMock.CreateAsync(destinationCreateInputModel); } ApplicationCloudinary.DeleteImage(ServiceProvider.GetRequiredService <Cloudinary>(), destinationDetailsViewModel.Name); var destinationsDbSet = this.DbContext.Destinations.OrderBy(r => r.CreatedOn); Assert.Equal(destinationsDbSet.Last().Id, destinationDetailsViewModel.Id); Assert.Equal(destinationsDbSet.Last().Name, destinationDetailsViewModel.Name); Assert.Equal(destinationsDbSet.Last().Country.Name, destinationDetailsViewModel.CountryName); }
private async Task DeleteOldMessage(string group) { var targetGroup = await this.db.Groups.FirstOrDefaultAsync(x => x.Name.ToLower() == group.ToLower()); if (targetGroup != null) { var messages = this.db.ChatMessages .Where(x => x.GroupId == targetGroup.Id) .OrderBy(x => x.SendedOn) .ToList(); if (messages.Count > GlobalConstants.SavedChatMessagesCount) { var oldMessages = messages.Take(messages.Count - GlobalConstants.SavedChatMessagesCount); foreach (var oldMessageId in oldMessages.Select(x => x.Id).ToList()) { var oldImages = this.db.ChatImages.Where(x => x.ChatMessageId == oldMessageId).ToList(); foreach (var oldImage in oldImages) { ApplicationCloudinary.DeleteImage( this.cloudinary, oldImage.Name, GlobalConstants.PrivateChatImagesFolder); } this.db.ChatImages.RemoveRange(oldImages); } this.db.ChatMessages.RemoveRange(oldMessages); await this.db.SaveChangesAsync(); } } }
public async Task <Tuple <bool, string> > DeleteChatTheme(DeleteChatThemeInputModel model) { var targetTheme = await this.db.ChatThemes.FirstOrDefaultAsync(x => x.Id == model.Id); if (targetTheme == null) { return(Tuple.Create( false, string.Format(ErrorMessages.ChatThemeDoesNotAlreadyExist, model.Name.ToUpper()))); } ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.ChatThemeName, targetTheme.Id), GlobalConstants.ChatThemesFolderName); var targetGroups = this.db.Groups.Where(x => x.ChatThemeId == targetTheme.Id); foreach (var group in targetGroups) { group.ChatThemeId = null; } this.db.Groups.UpdateRange(targetGroups); await this.db.SaveChangesAsync(); this.db.ChatThemes.Remove(targetTheme); await this.db.SaveChangesAsync(); return(Tuple.Create( true, string.Format(SuccessMessages.SuccessfullyDeleteChatTheme, model.Name.ToUpper()))); }
public async Task <Tuple <bool, string> > AddChatTheme(AddChatThemeInputModel model) { var targetTheme = await this.db.ChatThemes .FirstOrDefaultAsync(x => x.Name.ToUpper() == model.Name.ToUpper()); if (targetTheme != null) { return(Tuple.Create( false, string.Format(ErrorMessages.ChatThemeAlreadyExist, model.Name.ToUpper()))); } targetTheme = new ChatTheme { Name = model.Name, }; var imageUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, model.Image, string.Format(GlobalConstants.ChatThemeName, targetTheme.Id), GlobalConstants.ChatThemesFolderName); targetTheme.Url = imageUrl; this.db.ChatThemes.Add(targetTheme); await this.db.SaveChangesAsync(); return(Tuple.Create( true, string.Format(SuccessMessages.SuccessfullyAddedChatTheme, model.Name.ToUpper()))); }
public async Task <Tuple <bool, string> > AddChatStickers(AddChatStickersInputModel model) { var targetStickerType = await this.db.StickerTypes.FirstOrDefaultAsync(x => x.Id == model.StickerTypeId); if (targetStickerType != null) { var lastNumber = await this.db.Stickers .Where(x => x.StickerTypeId == targetStickerType.Id) .Select(x => x.Position) .OrderByDescending(x => x) .FirstOrDefaultAsync(); var notAddedStickersCount = 0; var addedStickersCount = 0; foreach (var file in model.Images) { string fileName = Path.GetFileNameWithoutExtension(file.FileName); if (this.db.Stickers.Any(x => x.Name.ToUpper() == fileName.ToUpper() && x.StickerTypeId == targetStickerType.Id)) { notAddedStickersCount++; } else { var sticker = new Sticker { Name = fileName.Length > 120 ? file.ToString().Substring(0, 120) : fileName, Position = lastNumber + 1, StickerTypeId = targetStickerType.Id, }; var imageUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, file, string.Format(GlobalConstants.StickerName, sticker.Id), GlobalConstants.StickersFolder); sticker.Url = imageUrl; lastNumber++; addedStickersCount++; this.db.Stickers.Add(sticker); await this.db.SaveChangesAsync(); } } return(Tuple.Create( true, string.Format( SuccessMessages.SuccessfullyAddedStickers, addedStickersCount, notAddedStickersCount))); } return(Tuple.Create(false, ErrorMessages.StickerTypeDoesNotExist)); }
public async Task DeleteCandidate(string id) { var targetCandidate = await this.db.JobCandidates.FirstOrDefaultAsync(x => x.Id == id); ApplicationCloudinary.DeleteImage(this.cloudinary, targetCandidate.CvName); this.db.JobCandidates.Remove(targetCandidate); await this.db.SaveChangesAsync(); }
public async Task <string> AddPartToSection(AddPartToSectionInputModel model) { var sectionName = await this.db.Sections .Where(x => x.Id == model.SectionId) .Select(x => x.Name) .FirstOrDefaultAsync(); int?lastPartPositionNumber = await this.db.SectionParts .Where(x => x.SectionId == model.SectionId) .OrderByDescending(x => x.PositionNumber) .Select(x => x.PositionNumber) .FirstOrDefaultAsync(); var part = new SectionPart { Name = model.Name, SectionId = model.SectionId, PartType = model.PartType, PositionNumber = lastPartPositionNumber == null ? 0 : (int)lastPartPositionNumber + 1, }; if (model.Heading != null || model.Subheading != null || model.Description != null) { part.PartText = new PartText { Heading = model.Heading, HeadingBg = model.HeadingBg, Subheading = model.Subheading, SubheadingBg = model.SubheadingBg, Description = model.SanitizeDescription, DescriptionBg = model.SanitizeDescriptionBg, SectionPartId = part.Id, }; } if (model.Image != null) { var imageUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, model.Image, $"PartImage-{part.Id}"); part.PartImage = new PartImage { Name = $"PartImage-{part.Id}", SectionPartId = part.Id, Url = imageUrl, }; } this.db.SectionParts.Add(part); await this.db.SaveChangesAsync(); return(sectionName); }
public async Task <Tuple <string, string> > AddProduct(ProductInputModel productInputModel) { if (this.db.Products.Any(x => x.Name.ToLower() == productInputModel.Name.ToLower())) { return(Tuple.Create( "Error", string.Format(ErrorMessages.ProductAlreadyExist, productInputModel.Name.ToUpper()))); } var targetCategory = await this.db.ProductCategories .FirstOrDefaultAsync(x => x.Title == productInputModel.ProductCategory); var product = new Product { Name = productInputModel.Name, Description = productInputModel.SanitaizedDescription, CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow, ProductCategoryId = targetCategory.Id, Price = productInputModel.Price, AvailableQuantity = productInputModel.AvailableQuantity, SpecificationsDescription = productInputModel.SanitaizedSpecifications, }; for (int i = 0; i < productInputModel.ProductImages.Count(); i++) { var imageName = string.Format(GlobalConstants.ProductImageName, product.Id, i); var imageUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, productInputModel.ProductImages.ElementAt(i), imageName, GlobalConstants.ShopProductsFolder); if (imageUrl != null) { var image = new ProductImage { ImageUrl = imageUrl, Name = imageName, ProductId = product.Id, }; product.ProductImages.Add(image); } } this.db.Products.Add(product); await this.db.SaveChangesAsync(); return(Tuple.Create( "Success", string.Format(SuccessMessages.SuccessfullyAddedProduct, product.Name.ToUpper()))); }
public void DeleteCloudinary(string id) { var settings = this.configuration["CloudSettings"].Split("$"); var cloudName = settings[0]; var apiKey = settings[1]; var apiSec = settings[2]; var account = new Account(cloudName, apiKey, apiSec); var cloud = new Cloudinary(account); ApplicationCloudinary.DeleteImage(cloud, id); }
public async Task <string> SaveCloudinaryAsync(IFormFile image) { var settings = this.configuration["CloudSettings"].Split("$"); var cloudName = settings[0]; var apiKey = settings[1]; var apiSec = settings[2]; var fileName = Guid.NewGuid().ToString(); var account = new Account(cloudName, apiKey, apiSec); var cloud = new Cloudinary(account); return(await ApplicationCloudinary.UploadImage(cloud, image, fileName)); }
public async Task <string> EditUserProfileAsync(UserEditInputModel model) { var user = await this.GetLoggedInUserAsync(); user.PhoneNumber = model.PhoneNumber; user.Email = model.Email; user.ProfileImage = await ApplicationCloudinary.UploadImage(cloudinary, model.ProfilePicture, Guid.NewGuid().ToString()); this.dbContext.Update(user); await this.dbContext.SaveChangesAsync(); return(user.Id); }
public async Task <Tuple <string, string> > DeletePost(string id, ApplicationUser user) { var post = this.db.Posts.FirstOrDefault(x => x.Id == id); var userPost = this.db.Users.FirstOrDefault(x => x.Id == post.ApplicationUserId); if (post != null && userPost != null) { if (post.ImageUrl != null) { ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.CloudinaryPostCoverImageName, post.Id), GlobalConstants.PostBaseImageFolder); } var allPostImages = this.db.PostImages .Where(x => x.PostId == post.Id) .ToList(); foreach (var postImage in allPostImages) { ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.CloudinaryPostImageName, postImage.Id), GlobalConstants.PostBaseImagesFolder); } if (user.Id == post.ApplicationUserId) { this.cyclicActivity.AddUserAction(user, UserActionsType.DeleteOwnPost, user); } else { this.cyclicActivity.AddUserAction(user, UserActionsType.DeletedPost, userPost); this.cyclicActivity.AddUserAction(userPost, UserActionsType.DeletePost, user); } var postActivities = this.db.UserActions.Where(x => x.PostId == post.Id); var comments = this.db.Comments.Where(x => x.PostId == post.Id).ToList(); this.db.Comments.RemoveRange(comments); this.db.UserActions.RemoveRange(postActivities); this.db.PostImages.RemoveRange(allPostImages); this.db.Posts.Remove(post); await this.db.SaveChangesAsync(); return(Tuple.Create("Success", SuccessMessages.SuccessfullyDeletePost)); } return(Tuple.Create("Error", SuccessMessages.SuccessfullyDeletePost)); }
public async Task <bool> UpdateUser(EditUserProfileInputModel model, string userId) { var user = await this.userRepo.All().FirstOrDefaultAsync(x => x.Id == userId); if (user == null) { return(false); } user.FirstName = model.FirstName; user.LastName = model.LastName; user.Description = model.Description; user.Gender = model.Gender; if (model.ProfileImage != null) { var imageName = Guid.NewGuid().ToString(); var imageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, model.ProfileImage, imageName); if (!string.IsNullOrEmpty(imageUrl)) { user.ProfileImage = new Image() { Url = imageUrl, Name = imageName, Creator = user, }; } } if (model.CoverImage != null) { var imageName = Guid.NewGuid().ToString(); var imageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, model.CoverImage, imageName); if (!string.IsNullOrEmpty(imageUrl)) { user.CoverImage = new Image() { Url = imageUrl, Name = imageName, Creator = user, }; } } this.userRepo.Update(user); await this.userRepo.SaveChangesAsync(); return(true); }
public async Task <Tuple <bool, string> > DeleteEmoji(DeleteEmojiInputModel model) { var emoji = await this.db.Emojis.FirstOrDefaultAsync(x => x.Id == model.Id); var emojiType = emoji.EmojiType; if (emoji != null) { string emojiName = emoji.Name; var emojiSkins = this.db.EmojiSkins.Where(x => x.EmojiId == emoji.Id).ToList(); foreach (var emojiSkin in emojiSkins) { ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.EmojiSkin, emojiSkin.Id), GlobalConstants.EmojisFolder); } ApplicationCloudinary.DeleteImage( this.cloudinary, string.Format(GlobalConstants.EmojiName, emoji.Id), GlobalConstants.EmojisFolder); this.db.EmojiSkins.RemoveRange(emojiSkins); this.db.Emojis.Remove(emoji); this.db.SaveChanges(); var targetToUpdate = this.db.Emojis .Where(x => x.EmojiType == emojiType) .OrderBy(x => x.Position) .ToList(); for (int i = 0; i < targetToUpdate.Count(); i++) { targetToUpdate[i].Position = i + 1; } this.db.Emojis.UpdateRange(targetToUpdate); await this.db.SaveChangesAsync(); return(Tuple.Create( true, string.Format(SuccessMessages.SuccessfullyDeleteEmoji, emojiName.ToUpper()))); } else { return(Tuple.Create(false, ErrorMessages.EmojiDoesNotExist)); } }
public async Task DeleteJobPosition(string id) { var position = await this.db.JobPositions.FirstOrDefaultAsync(x => x.Id == id); var positionCandidates = this.db.JobCandidates.Where(x => x.JobPositionId == id).ToList(); foreach (var candidate in positionCandidates) { ApplicationCloudinary.DeleteImage(this.cloudinary, candidate.CvName); } this.db.JobCandidates.RemoveRange(positionCandidates); this.db.JobPositions.Remove(position); await this.db.SaveChangesAsync(); }
public async Task <Image> CreateAsync(IFormFile imageSource) { var compleateUrl = await ApplicationCloudinary.UploadFileAsync(this.cloudinary, imageSource); var url = compleateUrl.Replace(this.imagePathPrefix, string.Empty); var image = new Image { Url = url }; await this.imagesRepository.AddAsync(image); await this.imagesRepository.SaveChangesAsync(); return(image); }
public async Task DeleteAsync(string id) { var image = this.imagesRepository .All() .FirstOrDefault(i => i.Id == id); if (image != null) { var avatarUrl = image.Url; this.imagesRepository.Delete(image); await this.imagesRepository.SaveChangesAsync(); await ApplicationCloudinary.DeleteFileAsync(this.cloudinary, avatarUrl); } }
public async Task <Images> SetAutomobileImages(ImagesInputModel model, Cloudinary cloudinary) { Images images = new Images(); if (model.ImageUrl1 != null) { images.ImageUrl1 = await ApplicationCloudinary.UploadImage(cloudinary, model.ImageUrl1, Guid.NewGuid().ToString()); } if (model.ImageUrl2 != null) { images.ImageUrl2 = await ApplicationCloudinary.UploadImage(cloudinary, model.ImageUrl2, Guid.NewGuid().ToString()); } if (model.ImageUrl3 != null) { images.ImageUrl3 = await ApplicationCloudinary.UploadImage(cloudinary, model.ImageUrl3, Guid.NewGuid().ToString()); } if (model.ImageUrl4 != null) { images.ImageUrl4 = await ApplicationCloudinary.UploadImage(cloudinary, model.ImageUrl4, Guid.NewGuid().ToString()); } if (model.ImageUrl5 != null) { images.ImageUrl5 = await ApplicationCloudinary.UploadImage(cloudinary, model.ImageUrl5, Guid.NewGuid().ToString()); } if (model.ImageUrl6 != null) { images.ImageUrl6 = await ApplicationCloudinary.UploadImage(cloudinary, model.ImageUrl6, Guid.NewGuid().ToString()); } if (model.ImageUrl7 != null) { images.ImageUrl7 = await ApplicationCloudinary.UploadImage(cloudinary, model.ImageUrl7, Guid.NewGuid().ToString()); } if (model.ImageUrl8 != null) { images.ImageUrl8 = await ApplicationCloudinary.UploadImage(cloudinary, model.ImageUrl8, Guid.NewGuid().ToString()); } if (model.ImageUrl9 != null) { images.ImageUrl9 = await ApplicationCloudinary.UploadImage(cloudinary, model.ImageUrl9, Guid.NewGuid().ToString()); } if (model.ImageUrl10 != null) { images.ImageUrl10 = await ApplicationCloudinary.UploadImage(cloudinary, model.ImageUrl10, Guid.NewGuid().ToString()); } return(images); }
// TODO: Add security public async Task <bool> UpdateUser(InputProfileSettingsModel model) { var entity = this.userRepository.All().Where(x => x.Id == model.Id).FirstOrDefault(); if (entity == null) { return(false); } entity.UserName = model.UserName; entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.AboutMe = model.AboutMe; entity.BirthDate = model.BirthDate; entity.PhoneNumber = model.PhoneNumber; var profileImageName = Guid.NewGuid().ToString(); var profileImageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, model.ProfileImageSource, profileImageName); if (!string.IsNullOrEmpty(profileImageUrl)) { entity.ProfileImage = new Media() { Url = profileImageUrl, Name = profileImageName, Creator = entity, }; } var coverImageName = Guid.NewGuid().ToString(); var coverImageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, model.CoverImageSource, coverImageName); if (!string.IsNullOrEmpty(coverImageUrl)) { entity.CoverImage = new Media() { Url = coverImageUrl, Name = coverImageName, Creator = entity, }; } this.userRepository.Update(entity); await this.userRepository.SaveChangesAsync(); return(true); }
public async Task AddSectionToPage(AddSectionToPageInputModel model) { int?lastSectionPositionNumber = await this.db.Sections .OrderByDescending(x => x.PositionNumber) .Select(x => x.PositionNumber) .FirstOrDefaultAsync(); var section = new Section { SectionType = model.SectionType, PageType = model.PageType, Name = model.Name, PositionNumber = lastSectionPositionNumber == null ? 0 : (int)lastSectionPositionNumber + 1, }; if (model.Heading != null || model.Subheading != null || model.Description != null) { section.PartText = new PartText { Heading = model.Heading, HeadingBg = model.HeadingBg, Subheading = model.Subheading, SubheadingBg = model.SubheadingBg, Description = model.SanitizeDescription, DescriptionBg = model.SanitizeDescriptionBg, SectionId = section.Id, }; } if (model.Image != null) { var imageUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, model.Image, $"SectionImage-{section.Id}"); section.PartImage = new PartImage { Name = $"SectionImage-{section.Id}", SectionId = section.Id, Url = imageUrl, }; } this.db.Sections.Add(section); await this.db.SaveChangesAsync(); }
public async Task <string> AddEmojis(AddEmojisInputModel model) { var addedEmojisCount = 0; var notAddedEmojisCount = 0; var lastNumber = await this.db.Emojis .Where(x => x.EmojiType == model.EmojiType) .Select(x => x.Position) .OrderByDescending(x => x) .FirstOrDefaultAsync(); foreach (var file in model.Images) { var fileName = Path.GetFileNameWithoutExtension(file.FileName); if (this.db.Emojis.Any(x => x.Name.ToUpper() == fileName.ToUpper() && x.EmojiType == model.EmojiType)) { notAddedEmojisCount++; } else { var emoji = new Emoji { Name = fileName, Position = lastNumber + 1, EmojiType = model.EmojiType, }; var emojiUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, file, string.Format(GlobalConstants.EmojiName, emoji.Id), GlobalConstants.EmojisFolder); emoji.Url = emojiUrl; lastNumber++; addedEmojisCount++; this.db.Emojis.Add(emoji); await this.db.SaveChangesAsync(); } } return(string.Format(SuccessMessages.SuccessfullyAddedEmojis, addedEmojisCount, notAddedEmojisCount)); }