Ejemplo n.º 1
0
        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> > 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())));
        }
Ejemplo n.º 3
0
        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 <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));
        }
Ejemplo n.º 5
0
        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)));
            }
        }
Ejemplo n.º 6
0
        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 <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));
        }
Ejemplo n.º 8
0
        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 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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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));
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
        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();
        }
Ejemplo n.º 15
0
        // 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);
        }
Ejemplo n.º 16
0
        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));
        }
Ejemplo n.º 17
0
        public async Task <DestinationDetailsViewModel> CreateAsync(DestinationCreateInputModel destinationCreateInputModel)
        {
            var country = await this.countriesRepository.All().FirstOrDefaultAsync(c => c.Id == destinationCreateInputModel.CountryId);

            if (country == null)
            {
                throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceCountryId, destinationCreateInputModel.CountryId));
            }

            // If destination exists return existing view model
            var destinationExists = this.destinationsRepository.All().Any(d =>
                                                                          d.Name == destinationCreateInputModel.Name && d.CountryId == destinationCreateInputModel.CountryId);

            if (destinationExists)
            {
                return(AutoMapper.Mapper
                       .Map <DestinationDetailsViewModel>(this.destinationsRepository.All()
                                                          .First(d => d.Name == destinationCreateInputModel.Name &&
                                                                 d.CountryId == destinationCreateInputModel.CountryId)));
            }

            var imageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, destinationCreateInputModel.Image, destinationCreateInputModel.Name);

            var googleServiceInfo =
                DateTimeExtensions.GetGoogleServiceInfo(destinationCreateInputModel.Name, country.Name);

            var destination = new Destination
            {
                Name         = destinationCreateInputModel.Name,
                CountryId    = destinationCreateInputModel.CountryId,
                ImageUrl     = imageUrl,
                Information  = destinationCreateInputModel.Information,
                Latitude     = googleServiceInfo.Latitude,
                Longitude    = googleServiceInfo.Longitude,
                UtcRawOffset = googleServiceInfo.UtcRawOffset,
            };

            this.destinationsRepository.Add(destination);
            await this.destinationsRepository.SaveChangesAsync();

            var destinationDetailsViewModel = AutoMapper.Mapper.Map <DestinationDetailsViewModel>(destination);

            return(destinationDetailsViewModel);
        }
Ejemplo n.º 18
0
        public async Task <Tuple <bool, string> > AddNewSticker(AddChatStickerInputModel model)
        {
            var targetType = await this.db.StickerTypes.FirstOrDefaultAsync(x => x.Id == model.StickerTypeId);

            if (targetType != null)
            {
                var sticker = await this.db.Stickers
                              .FirstOrDefaultAsync(x => x.Name.ToUpper() == model.Name.ToUpper() && x.StickerTypeId == model.StickerTypeId);

                if (sticker == null)
                {
                    sticker = new Sticker
                    {
                        Name          = model.Name,
                        StickerTypeId = targetType.Id,
                        Position      = await this.db.Stickers
                                        .Where(x => x.StickerTypeId == targetType.Id)
                                        .Select(x => x.Position).OrderByDescending(x => x)
                                        .FirstOrDefaultAsync() + 1,
                    };

                    var imageUrl = await ApplicationCloudinary.UploadImage(
                        this.cloudinary,
                        model.Image,
                        string.Format(GlobalConstants.StickerName, sticker.Id),
                        GlobalConstants.StickersFolder);

                    sticker.Url = imageUrl;

                    this.db.Stickers.Add(sticker);
                    await this.db.SaveChangesAsync();

                    return(Tuple.Create(
                               true,
                               string.Format(SuccessMessages.SuccessfullyAddedSticker, sticker.Name.ToUpper())));
                }

                return(Tuple.Create(
                           false,
                           string.Format(ErrorMessages.StickerAlreadyExist, model.Name.ToUpper())));
            }

            return(Tuple.Create(false, ErrorMessages.StickerTypeDoesNotExist));
        }
Ejemplo n.º 19
0
        public async Task ApplyForJob(JobCandidateInputModel model)
        {
            var isExist = await this.db.JobCandidates
                          .FirstOrDefaultAsync(x => x.Phonenumber == model.Phonenumber &&
                                               x.Email == model.Email &&
                                               x.JobPositionId == model.JobPositionId);

            if (isExist == null)
            {
                isExist = new JobCandidate
                {
                    FirstName     = model.FirstName,
                    LastName      = model.LastName,
                    Email         = model.Email,
                    Phonenumber   = model.Phonenumber,
                    JobPositionId = model.JobPositionId,
                };

                var cvUrl = await ApplicationCloudinary.UploadImage(
                    this.cloudinary,
                    model.CV,
                    $"{isExist.Id}-{model.CV.FileName}");

                isExist.CvUrl  = cvUrl;
                isExist.CvName = $"{isExist.Id}-{model.CV.FileName}";
                this.db.JobCandidates.Add(isExist);
            }
            else
            {
                isExist.FirstName = model.FirstName;
                isExist.LastName  = model.LastName;
                ApplicationCloudinary.DeleteImage(this.cloudinary, isExist.CvName);
                var cvUrl = await ApplicationCloudinary.UploadImage(
                    this.cloudinary,
                    model.CV,
                    $"{isExist.Id}-{model.CV.FileName}");

                isExist.CvUrl  = cvUrl;
                isExist.CvName = $"{isExist.Id}-{model.CV.FileName}";
                this.db.JobCandidates.Update(isExist);
            }

            await this.db.SaveChangesAsync();
        }
Ejemplo n.º 20
0
        public async Task <Tuple <bool, string> > AddNewHolidayTheme(AddHolidayThemeInputModel model)
        {
            var targetTheme = await this.db.HolidayThemes
                              .FirstOrDefaultAsync(x => x.Name.ToUpper() == model.Name.ToUpper());

            if (targetTheme == null)
            {
                targetTheme = new HolidayTheme
                {
                    Name     = model.Name,
                    IsActive = false,
                };

                foreach (var icon in model.Icons)
                {
                    var targetIcon = new HolidayIcon
                    {
                        Name = Path.GetFileNameWithoutExtension(icon.FileName),
                    };

                    var iconUrl = await ApplicationCloudinary.UploadImage(
                        this.cloudinary,
                        icon,
                        string.Format(GlobalConstants.HolidayIconName, targetIcon.Id),
                        GlobalConstants.HolidayThemesFolder);

                    targetIcon.Url = iconUrl;
                    targetTheme.HolidayIcons.Add(targetIcon);
                }

                this.db.HolidayThemes.Add(targetTheme);
                await this.db.SaveChangesAsync();

                return(Tuple.Create(
                           true,
                           string.Format(SuccessMessages.SuccessfullyAddedHolidayTheme, targetTheme.Name.ToUpper())));
            }

            return(Tuple.Create(
                       false,
                       string.Format(ErrorMessages.HolidayThemeAlreadyExist, model.Name.ToUpper())));
        }
Ejemplo n.º 21
0
        public async Task EditAsync(ActivityEditViewModel activityToEditViewModel)
        {
            if (!Enum.TryParse(activityToEditViewModel.Type, true, out ActivityType activityTypeEnum))
            {
                throw new ArgumentException(string.Format(ServicesDataConstants.InvalidActivityType, activityToEditViewModel.Type));
            }

            var activity = await this.activitiesRepository.All().FirstOrDefaultAsync(a => a.Id == activityToEditViewModel.Id);

            if (activity == null)
            {
                throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceActivityId, activityToEditViewModel.Id));
            }

            var destination = await this.destinationsRepository.All().FirstOrDefaultAsync(l => l.Id == activityToEditViewModel.DestinationId);

            if (destination == null)
            {
                throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceDestinationId, activityToEditViewModel.DestinationId));
            }

            if (activityToEditViewModel.NewImage != null)
            {
                var newImageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, activityToEditViewModel.NewImage, activityToEditViewModel.Name);

                activity.ImageUrl = newImageUrl;
            }

            activity.Name           = activityToEditViewModel.Name;
            activity.Type           = activityTypeEnum;
            activity.Date           = activityToEditViewModel.Date;
            activity.Description    = activityToEditViewModel.Description;
            activity.AdditionalInfo = activityToEditViewModel.AdditionalInfo;
            activity.Destination    = destination;
            activity.Address        = activityToEditViewModel.Address;
            activity.LocationName   = activityToEditViewModel.LocationName;
            activity.Price          = activityToEditViewModel.Price;

            this.activitiesRepository.Update(activity);
            await this.activitiesRepository.SaveChangesAsync();
        }
Ejemplo n.º 22
0
        public async Task <ActivityDetailsViewModel> CreateAsync(ActivityCreateInputModel activityCreateInputModel)
        {
            if (!Enum.TryParse(activityCreateInputModel.Type, true, out ActivityType activityTypeEnum))
            {
                throw new ArgumentException(string.Format(ServicesDataConstants.InvalidActivityType, activityCreateInputModel.Type));
            }

            var destination = await this.destinationsRepository.All().FirstOrDefaultAsync(l => l.Id == activityCreateInputModel.DestinationId);

            if (destination == null)
            {
                throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceDestinationId, activityCreateInputModel.DestinationId));
            }

            var imageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, activityCreateInputModel.Image, activityCreateInputModel.Name);

            // var utcDate = activityCreateInputModel.Date.GetUtcDate(destination.Name, destination.Country.Name);
            var utcDate = activityCreateInputModel.Date.CalculateUtcDateTime(destination.UtcRawOffset);

            var activity = new Activity
            {
                Name           = activityCreateInputModel.Name,
                ImageUrl       = imageUrl,
                Date           = utcDate,
                Type           = activityTypeEnum,
                Description    = activityCreateInputModel.Description,
                AdditionalInfo = activityCreateInputModel.AdditionalInfo,
                Destination    = destination,
                Address        = activityCreateInputModel.Address,
                LocationName   = activityCreateInputModel.LocationName,
                Price          = activityCreateInputModel.Price,
            };

            this.activitiesRepository.Add(activity);
            await this.activitiesRepository.SaveChangesAsync();

            var activityDetailsViewModel = AutoMapper.Mapper.Map <ActivityDetailsViewModel>(activity);

            return(activityDetailsViewModel);
        }
Ejemplo n.º 23
0
        public async Task <RestaurantDetailsViewModel> CreateAsync(RestaurantCreateInputModel restaurantCreateInputModel)
        {
            if (!Enum.TryParse(restaurantCreateInputModel.Type, true, out RestaurantType typeEnum))
            {
                throw new ArgumentException(string.Format(ServicesDataConstants.InvalidRestaurantType, restaurantCreateInputModel.Type));
            }

            // If destination exists return existing view model
            var restaurantExists = this.restaurantsRepository.All().Any(
                r => r.Name == restaurantCreateInputModel.Name &&
                r.DestinationId == restaurantCreateInputModel.DestinationId);

            if (restaurantExists)
            {
                return(AutoMapper.Mapper
                       .Map <RestaurantDetailsViewModel>(this.restaurantsRepository.All()
                                                         .First(r => r.Name == restaurantCreateInputModel.Name &&
                                                                r.DestinationId == restaurantCreateInputModel.DestinationId)));
            }

            var imageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, restaurantCreateInputModel.Image, restaurantCreateInputModel.Name);

            var restaurant = new Restaurant()
            {
                Name          = restaurantCreateInputModel.Name,
                Address       = restaurantCreateInputModel.Address,
                DestinationId = restaurantCreateInputModel.DestinationId,
                ImageUrl      = imageUrl,
                Type          = typeEnum,
                Seats         = restaurantCreateInputModel.Seats,
            };

            this.restaurantsRepository.Add(restaurant);
            await this.restaurantsRepository.SaveChangesAsync();

            var restaurantDetailsViewModel = AutoMap.Mapper.Map <RestaurantDetailsViewModel>(restaurant);

            return(restaurantDetailsViewModel);
        }
Ejemplo n.º 24
0
        public async Task Create(WeetCreateModel model, ApplicationUser user)
        {
            var entity = new Weet()
            {
                Id      = Guid.NewGuid().ToString(),
                Author  = user,
                Content = model.Content,
            };

            if (!string.IsNullOrWhiteSpace(model.Tags))
            {
                entity.Tags = await this.ConvertToTags(entity.Id, model.Tags);
            }

            var imageName = Guid.NewGuid().ToString();
            var imageUrl  = await ApplicationCloudinary.UploadImage(this.cloudinary, model.Image, imageName);

            if (!string.IsNullOrEmpty(imageUrl))
            {
                entity.Image = new Media()
                {
                    Url     = imageUrl,
                    Name    = imageName,
                    Creator = user,
                };

                var tagId = await this.tagsService.GetTagId("Images");

                entity.Tags.Add(new WeetTag()
                {
                    TagId = tagId, WeetId = entity.Id
                });
            }

            await this.weetRepository.AddAsync(entity);

            await this.weetRepository.SaveChangesAsync();
        }
Ejemplo n.º 25
0
        public async Task <Tuple <bool, string> > EditChatTheme(EditChatThemeInputModel model)
        {
            var targetTheme = await this.db.ChatThemes.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (targetTheme == null)
            {
                return(Tuple.Create(
                           false, ErrorMessages.ChatThemeDoesNotAlreadyExist));
            }

            if (this.db.ChatThemes.Any(x => x.Name.ToUpper() == model.Name.ToUpper()) && model.Image == null)
            {
                return(Tuple.Create(
                           false,
                           string.Format(ErrorMessages.ChatThemeAlreadyExist, model.Name.ToUpper())));
            }

            if (model.Image != null)
            {
                string imageUrl =
                    await ApplicationCloudinary.UploadImage(
                        this.cloudinary,
                        model.Image,
                        string.Format(GlobalConstants.ChatThemeName, targetTheme.Id),
                        GlobalConstants.ChatThemesFolderName);

                targetTheme.Url = imageUrl;
            }

            targetTheme.Name = model.Name;
            this.db.ChatThemes.Update(targetTheme);
            await this.db.SaveChangesAsync();

            return(Tuple.Create(
                       true,
                       string.Format(SuccessMessages.SuccessfullyEditChatTheme, model.Name.ToUpper())));
        }
Ejemplo n.º 26
0
        public async Task EditAsync(RestaurantEditViewModel restaurantEditViewModel)
        {
            if (!Enum.TryParse(restaurantEditViewModel.Type, true, out RestaurantType restaurantTypeEnum))
            {
                throw new ArgumentException(string.Format(ServicesDataConstants.InvalidRestaurantType, restaurantEditViewModel.Type));
            }

            var restaurant = this.restaurantsRepository.All().FirstOrDefault(r => r.Id == restaurantEditViewModel.Id);

            if (restaurant == null)
            {
                throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceRestaurantId, restaurantEditViewModel.Id));
            }

            var destination = this.destinationsRepository.All().FirstOrDefault(d => d.Id == restaurantEditViewModel.DestinationId);

            if (destination == null)
            {
                throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceDestinationId, restaurantEditViewModel.DestinationId));
            }

            if (restaurantEditViewModel.NewImage != null)
            {
                var newImageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, restaurantEditViewModel.NewImage, restaurantEditViewModel.Name);

                restaurant.ImageUrl = newImageUrl;
            }

            restaurant.Name        = restaurantEditViewModel.Name;
            restaurant.Address     = restaurantEditViewModel.Address;
            restaurant.Destination = destination;
            restaurant.Seats       = restaurantEditViewModel.Seats;
            restaurant.Type        = restaurantTypeEnum;

            this.restaurantsRepository.Update(restaurant);
            await this.restaurantsRepository.SaveChangesAsync();
        }
Ejemplo n.º 27
0
        public async Task <int?> CreateAsync(PostInputModel model, string userId, int groupId = 0)
        {
            var entity = new Post()
            {
                Content   = model.Content,
                CreatorId = userId,
                Privacy   = model.Privacy,
            };

            if (groupId != 0)
            {
                entity.GroupId = groupId;
            }

            if (model.Image != null)
            {
                var imageName = Guid.NewGuid().ToString();
                var imageUrl  = await ApplicationCloudinary.UploadImage(this.cloudinary, model.Image, imageName);

                if (!string.IsNullOrEmpty(imageUrl))
                {
                    entity.Image = new Image()
                    {
                        Url       = imageUrl,
                        Name      = imageName,
                        CreatorId = userId,
                    };
                }
            }

            await this.postsRepo.AddAsync(entity);

            await this.postsRepo.SaveChangesAsync();

            return(entity?.Id);
        }
Ejemplo n.º 28
0
        public async Task <Tuple <bool, string> > EditEmoji(EditEmojiInputModel 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())));
            }

            var targetEmoji = await this.db.Emojis.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (targetEmoji != null)
            {
                if (model.Image != null)
                {
                    var imageUrl = await ApplicationCloudinary.UploadImage(
                        this.cloudinary,
                        model.Image,
                        string.Format(GlobalConstants.EmojiName, model.Id),
                        GlobalConstants.EmojisFolder);

                    targetEmoji.Url = imageUrl;
                }

                targetEmoji.Name      = model.Name;
                targetEmoji.EmojiType = model.EmojiType;
                this.db.Emojis.Update(targetEmoji);
                await this.db.SaveChangesAsync();

                return(Tuple.Create(
                           true,
                           string.Format(SuccessMessages.SuccessfullyEditedEmoji, model.Name.ToUpper())));
            }
            else
            {
                return(Tuple.Create(false, ErrorMessages.EmojiDoesNotExist));
            }
        }
        public async Task <Tuple <string, string> > EditProduct(EditProductInputModel inputModel)
        {
            var product = await this.db.Products.FirstOrDefaultAsync(x => x.Id == inputModel.Id);

            if (product != null)
            {
                var category = await this.db.ProductCategories
                               .FirstOrDefaultAsync(x => x.Title.ToLower() == inputModel.ProductCategory.ToLower());

                if (category != null)
                {
                    product.ProductCategoryId = category.Id;
                    product.Name                      = inputModel.Name;
                    product.Description               = inputModel.SanitaizedDescription;
                    product.AvailableQuantity         = inputModel.AvailableQuantity;
                    product.SpecificationsDescription = inputModel.SanitaizedSpecifications;
                    product.Price                     = inputModel.Price;
                    product.UpdatedOn                 = DateTime.UtcNow;

                    if (inputModel.ProductImages.Count != 0)
                    {
                        var images = this.db.ProductImages.Where(x => x.ProductId == inputModel.Id).ToList();

                        foreach (var image in images)
                        {
                            ApplicationCloudinary.DeleteImage(this.cloudinary, image.Name);
                        }

                        this.db.ProductImages.RemoveRange(images);
                        await this.db.SaveChangesAsync();

                        for (int i = 0; i < inputModel.ProductImages.Count(); i++)
                        {
                            var imageName = string.Format(GlobalConstants.ProductImageName, product.Id, i);

                            var imageUrl =
                                await ApplicationCloudinary.UploadImage(
                                    this.cloudinary,
                                    inputModel.ProductImages.ElementAt(i),
                                    imageName);

                            if (imageUrl != null)
                            {
                                var image = new ProductImage
                                {
                                    ImageUrl  = imageUrl,
                                    Name      = imageName,
                                    ProductId = product.Id,
                                };

                                product.ProductImages.Add(image);
                            }
                        }
                    }

                    this.db.Products.Update(product);
                    await this.db.SaveChangesAsync();

                    return(Tuple.Create("Success", SuccessMessages.SuccessfullyEditedProduct));
                }

                return(Tuple.Create("Error", ErrorMessages.InvalidInputModel));
            }

            return(Tuple.Create("Error", ErrorMessages.InvalidInputModel));
        }
Ejemplo n.º 30
0
        public async Task <Tuple <string, string> > CreatePost(CreatePostIndexModel model, ApplicationUser user)
        {
            var category = await this.db.Categories
                           .FirstOrDefaultAsync(x => x.Name.ToUpper() == model.PostInputModel.CategoryName.ToUpper());

            if (category == null)
            {
                return(Tuple.Create("Error", ErrorMessages.InvalidInputModel));
            }

            var contentWithoutTags = Regex.Replace(model.PostInputModel.SanitizeContent, "<.*?>", string.Empty);

            var post = new Post
            {
                Title        = model.PostInputModel.Title,
                CategoryId   = category.Id,
                Content      = model.PostInputModel.SanitizeContent,
                CreatedOn    = DateTime.UtcNow,
                ShortContent = contentWithoutTags.Length <= GlobalConstants.BlogPostShortContentMaxLength ?
                               contentWithoutTags :
                               $"{contentWithoutTags.Substring(0, GlobalConstants.BlogPostShortContentMaxLength)}...",
                ApplicationUserId = user.Id,
            };

            var imageUrl = await ApplicationCloudinary.UploadImage(
                this.cloudinary,
                model.PostInputModel.CoverImage,
                string.Format(GlobalConstants.CloudinaryPostCoverImageName, post.Id),
                GlobalConstants.PostBaseImageFolder);

            var canUploadPostImages = (await this.userManager.IsInRoleAsync(user, GlobalConstants.AdministratorRole)) ||
                                      (await this.userManager.IsInRoleAsync(user, GlobalConstants.EditorRole)) ||
                                      (await this.userManager.IsInRoleAsync(user, GlobalConstants.AuthorRole));

            if (canUploadPostImages)
            {
                for (int i = 0; i < model.PostInputModel.PostImages.Count; i++)
                {
                    var image = model.PostInputModel.PostImages.ElementAt(i);

                    var postImage = new PostImage
                    {
                        PostId = post.Id,
                        Name   = string.Format(GlobalConstants.BlogPostImageNameTemplate, i + 1),
                    };

                    var postImageUrl = await ApplicationCloudinary.UploadImage(
                        this.cloudinary,
                        image,
                        string.Format(GlobalConstants.CloudinaryPostImageName, postImage.Id),
                        GlobalConstants.PostBaseImagesFolder);

                    postImage.Url = postImageUrl ?? string.Empty;
                    post.PostImages.Add(postImage);
                }
            }

            if (imageUrl != null)
            {
                post.ImageUrl = imageUrl;
            }

            foreach (var tagName in model.PostInputModel.TagsNames)
            {
                var tag = await this.db.Tags
                          .FirstOrDefaultAsync(x => x.Name.ToUpper() == tagName.ToUpper());

                if (tag != null)
                {
                    post.PostsTags.Add(new PostTag
                    {
                        PostId = post.Id,
                        TagId  = tag.Id,
                    });
                }
            }

            var adminRole = await this.roleManager.FindByNameAsync(Roles.Administrator.ToString());

            var editorRole = await this.roleManager.FindByNameAsync(Roles.Editor.ToString());

            var allAdminIds = this.db.UserRoles
                              .Where(x => x.RoleId == adminRole.Id)
                              .Select(x => x.UserId)
                              .ToList();
            var allEditorIds = this.db.UserRoles
                               .Where(x => x.RoleId == editorRole.Id)
                               .Select(x => x.UserId)
                               .ToList();
            var specialIds = allAdminIds.Union(allEditorIds).ToList();

            if (await this.userManager.IsInRoleAsync(user, Roles.Administrator.ToString()) ||
                await this.userManager.IsInRoleAsync(user, Roles.Editor.ToString()) ||
                await this.userManager.IsInRoleAsync(user, Roles.Author.ToString()))
            {
                post.PostStatus = PostStatus.Approved;
                var followerIds = this.db.FollowUnfollows
                                  .Where(x => x.ApplicationUserId == user.Id && !specialIds.Contains(x.FollowerId))
                                  .Select(x => x.FollowerId)
                                  .ToList();
                specialIds = specialIds.Union(followerIds).ToList();
                specialIds.Remove(user.Id);
            }
            else
            {
                post.PostStatus = PostStatus.Pending;
                this.db.PendingPosts.Add(new PendingPost
                {
                    ApplicationUserId = post.ApplicationUserId,
                    PostId            = post.Id,
                    IsPending         = true,
                });
            }

            foreach (var specialId in specialIds)
            {
                var toUser = await this.userManager.FindByIdAsync(specialId);

                string notificationId =
                    await this.notificationService.AddBlogPostNotification(toUser, user, post.ShortContent, post.Id);

                var count = await this.notificationService.GetUserNotificationsCount(toUser.UserName);

                await this.notificationHubContext
                .Clients
                .User(toUser.Id)
                .SendAsync("ReceiveNotification", count, true);

                var notification = await this.notificationService.GetNotificationById(notificationId);

                await this.notificationHubContext.Clients.User(toUser.Id)
                .SendAsync("VisualizeNotification", notification);
            }

            this.db.Posts.Add(post);

            this.nonCyclicActivity.AddUserAction(
                new CreatePostUserAction
            {
                ApplicationUser   = user,
                ApplicationUserId = user.Id,
                PostId            = post.Id,
                Post = post,
            });
            await this.db.SaveChangesAsync();

            return(Tuple.Create("Success", SuccessMessages.SuccessfullyCreatedPost));
        }