Пример #1
0
        public async Task <int> CreateCar(string userId, AddCarInputModel input)
        {
            var newCar = new Car()
            {
                UserId     = userId,
                MakeId     = input.MakeId,
                Model      = input.Model,
                TopSpeed   = input.TopSpeed,
                Weight     = input.Weight,
                Horsepower = input.Horsepower,
                Year       = input.Year,
                Torque     = input.Torque,
            };

            if (input.MainImage != null)
            {
                var carMainImageUrl = await CloudinaryExtension.UploadFileAsync(this.cloudinary, input.MainImage);

                newCar.MainImageUrl = carMainImageUrl;
            }

            await this.carRepository.AddAsync(newCar);

            await this.carRepository.SaveChangesAsync();

            return(newCar.Id);
        }
Пример #2
0
        public async Task <int> CreatePost(string userId, CreatePostInputModel input)
        {
            var postImages = new List <PostImage>();

            if (input.Images != null)
            {
                var postImagesUrls = await CloudinaryExtension.UploadAsync(this.cloudinary, input.Images);

                foreach (var url in postImagesUrls)
                {
                    postImages.Add(new PostImage()
                    {
                        ImageUrl = url
                    });
                }
            }

            var newPost = new Post()
            {
                Images      = postImages,
                UserId      = userId,
                Description = input.Description,
            };

            await this.posts.AddAsync(newPost);

            await this.posts.SaveChangesAsync();

            return(newPost.Id);
        }
Пример #3
0
        public async Task <IActionResult> Upload(ICollection <IFormFile> files)
        {
            var result = await CloudinaryExtension.UploadAsync(this.cloudinary, files);

            this.ViewBag.links = result;

            return(Redirect("/"));
        }
        public async Task <IActionResult> UploadForm(ICollection <IFormFile> files)
        {
            var result = await CloudinaryExtension.UploadAsync(this.cloudinary, files);

            this.ViewData["Links"] = result;

            return(this.View());
        }
Пример #5
0
        public async Task ChangeCoverPhoto(NewProfilePhotoInputModel input)
        {
            if (input.ProfilePhoto != null)
            {
                var user             = this.users.All().FirstOrDefault(u => u.Id == input.UserId);
                var newCoverPhotoUrl = await CloudinaryExtension.UploadFileAsync(this.cloudinary, input.ProfilePhoto);

                user.CoverPhotoUrl = newCoverPhotoUrl;
                await this.users.SaveChangesAsync();
            }
        }
Пример #6
0
        private async Task <string> UploadImageToCloudinaryAsync(IFormFile image)
        {
            var transformation = new Transformation()
                                 .Height(GlobalConstants.ImageHeight)
                                 .Width(GlobalConstants.ImageWidth)
                                 .Crop(GlobalConstants.CropImagePad);

            var imageUri = await CloudinaryExtension.UploadImageAsync(this.cloudinary, image, transformation);

            var imagePath = imageUri.Replace(GlobalConstants.CloudinaryUploadDir, string.Empty);

            return(imagePath);
        }
Пример #7
0
        public async Task <IActionResult> CreateAsync(ProjectCreateInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var imageUrls = await CloudinaryExtension.UploadMultipleAsync(this.cloudinary, input.Pictures);

            int projectId = await this.projectsService.CreateAsync(input.CategoryId, input.Content, input.Title, input.ProjectStatus, input.Progress, user.Id, imageUrls);

            return(this.RedirectToAction("ById", new { id = projectId }));
        }
        public async Task <IActionResult> Upload(ICollection <IFormFile> files)
        {
            await CloudinaryExtension.UploadAsync(this.cloudinary, files);

            return(this.Redirect("/"));

            // var uploadParams = new ImageUploadParams()
            // {
            //    File = new FileDescription(@"D:\DemoProject\DataImports\product_1.jpg"),
            // };

            // var uploadResult = await this.cloudinary.UploadAsync(uploadParams);

            // return this.Redirect("/");
        }
Пример #9
0
        public async Task <IActionResult> CreateAsync(PictureCreateInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var imageUrl = await CloudinaryExtension.UploadSingleAsync(this.cloudinary, input.Picture);

            _ = await this.galleryService.CreateAsync(input.Type, imageUrl, user.Id);

            return(this.RedirectToAction($"All{input.Type}s"));
        }
Пример #10
0
        public async Task <IActionResult> AddAsync([FromRoute] string id, InputWinViewModel input, IFormFile file)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            input.Url = await CloudinaryExtension.UploadAsync(this.cloudinary, file);

            var gamingHallId = await this.services.AddAsync(input.Url, input.Description, input.Date, id, input.SlotMachineId);

            this.TempData["Message"] = "Win was added successfully!";

            return(this.Redirect("/Wins/All/" + gamingHallId));
        }
        public async Task <IActionResult> Update(UpdateHallViewModel input, IFormFile file)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            if (file != null)
            {
                input.ImageUrl = await CloudinaryExtension.UploadAsync(this.cloudinary, file);
            }

            await this.service.UpdateAsync(input.Id, input.HallName, input.ImageUrl, input.Description, input.PhoneNumber, input.Adress, input.Town);

            this.TempData["Message"] = "Gaming hall was edited successfully!";
            return(this.Redirect("/GamingHall/Halls"));
        }
        public async Task <IActionResult> AddAsync([FromRoute] string id, ICollection <IFormFile> files)
        {
            if (files.Count == 0)
            {
                return(this.View());
            }

            var urls = await CloudinaryExtension.UploadManyAsync(this.cloudinary, files);

            foreach (var url in urls)
            {
                await this.services.AddAsync(url, id);
            }

            this.TempData["Message"] = "Pictures was added successfully!";

            return(this.Redirect("/Gallery/All/" + id));
        }
Пример #13
0
        public async Task <IActionResult> CreateAsync(LocationsCreateInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var imageUrls = await CloudinaryExtension.UploadMultipleAsync(this.cloudinary, input.Pictures);

            string latinName = Transliteration.CyrillicToLatin(input.Name, Language.Bulgarian);

            latinName = latinName.Replace(' ', '-');
            _         = await this.locationsService.CreateAsync(input.Name, input.Description, input.Adress, input.PhoneNumber, input.Email, input.Website, input.FacebookPage, input.InstagramPage, user.Id, input.MapLink, input.Perks, input.Type, imageUrls, latinName);

            return(this.RedirectToAction("ByName", new { name = latinName }));
        }
Пример #14
0
        public async Task <IActionResult> CreateAsync(NewsCreateInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var imageUrls = await CloudinaryExtension.UploadMultipleAsync(this.cloudinary, input.Pictures);

            string latinTitle = Transliteration.CyrillicToLatin(input.Title, Language.Bulgarian);

            latinTitle = latinTitle.Replace(' ', '-');
            _          = await this.newsService.CreateAsync(input.Title, input.Content, user.Id, imageUrls, latinTitle, input.Author);

            return(this.RedirectToAction("ByName", new { name = latinTitle }));
        }
        public async Task <IActionResult> Add(InputGamingHallViewModel input, IFormFile file)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            if (file != null)
            {
                input.ImageUrl = await CloudinaryExtension.UploadAsync(this.cloudinary, file);
            }

            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            await this.service.AddAsync(input.HallName, input.ImageUrl, input.Description, input.PhoneNumber, input.Adress, input.Town, userId);

            this.TempData["Message"] = "Gaming hall was aded successfully!";
            return(this.Redirect("/GamingHall/Halls"));
        }
Пример #16
0
        public async Task <IActionResult> Edit(LocationsEditViewModel locationToEdit)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var imageUrls = new List <string>();

            if (locationToEdit.Pictures != null)
            {
                imageUrls = await CloudinaryExtension.UploadMultipleAsync(this.cloudinary, locationToEdit.Pictures);
            }

            string latinName = Transliteration.CyrillicToLatin(locationToEdit.Name, Language.Bulgarian);

            latinName = latinName.Replace(' ', '-');

            await this.locationsService.EditAsync(locationToEdit.Name, locationToEdit.Description, locationToEdit.Adress, locationToEdit.PhoneNumber, locationToEdit.Email, locationToEdit.Website, locationToEdit.FacebookPage, locationToEdit.InstagramPage, user.Id, locationToEdit.MapLink, locationToEdit.Perks, locationToEdit.Type, imageUrls, latinName, locationToEdit.Id);

            return(this.RedirectToAction("ByName", new { name = latinName }));
        }
Пример #17
0
        public async Task <IActionResult> Edit(NewsEditViewModel newsPostToEdit)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var imageUrl = string.Empty;

            if (newsPostToEdit.Picture != null)
            {
                imageUrl = await CloudinaryExtension.UploadSingleAsync(this.cloudinary, newsPostToEdit.Picture);
            }

            string latinTitle = Transliteration.CyrillicToLatin(newsPostToEdit.Title, Language.Bulgarian);

            latinTitle = latinTitle.Replace(' ', '-');

            await this.newsService.EditAsync(newsPostToEdit.Title, newsPostToEdit.Content, user.Id, imageUrl, latinTitle, newsPostToEdit.Author, newsPostToEdit.Id);

            return(this.RedirectToAction("ByName", new { name = latinTitle }));
        }
Пример #18
0
        public async Task <IActionResult> Edit(AwardsEditViewModel awardToEdit)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var imageUrl = string.Empty;

            if (awardToEdit.Picture != null)
            {
                imageUrl = await CloudinaryExtension.UploadSingleAsync(this.cloudinary, awardToEdit.Picture);
            }

            string latinName = Transliteration.CyrillicToLatin(awardToEdit.Name, Language.Bulgarian);

            latinName = latinName.Replace(' ', '-');

            await this.awardsService.EditAsync(awardToEdit.Name, latinName, awardToEdit.Date, awardToEdit.Location, awardToEdit.Place, imageUrl, user.Id, awardToEdit.Id);

            return(this.RedirectToAction("All"));
        }
Пример #19
0
        public async Task <IActionResult> CreateAsync(AwardsCreateInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var imageUrl = await CloudinaryExtension.UploadSingleAsync(this.cloudinary, input.Picture);

            string latinName = Transliteration.CyrillicToLatin(input.Name, Language.Bulgarian);

            latinName = latinName.Replace(' ', '-');

            _ = await this.awardsService.CreateAsync(input.Name, latinName, input.Date, input.Location, input.Place, imageUrl, user.Id);

            return(this.RedirectToAction("All"));
        }
        public async Task <IActionResult> AddImage(ImagePostInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input.LocationsDropDown = this.locationsService.GetAllLocationsAsKeyValuePair();
                input.CamerasDropDown   = this.cameraService.GetAllCamerasAsKeyValuePair();
                input.TagsDropDown      = this.tagsService.GetAllTagsAsKeyValuePair();

                return(this.View(input));
            }

            var imageInfo = await CloudinaryExtension.UploadImageAsync(this.cloudinary, input.Image);

            var user = await this.userManager.GetUserAsync(this.User);

            await this.postsService.CreateImagePostAsync(input, user.Id, imageInfo);

            return(this.Redirect("/"));
        }
Пример #21
0
        public async Task <IActionResult> CreateAsync(DancesCreateInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var imageUrl = await CloudinaryExtension.UploadSingleAsync(this.cloudinary, input.Picture);

            string latinName = Transliteration.CyrillicToLatin(input.Name, Language.Bulgarian);

            latinName = latinName.Replace(' ', '-');

            _ = await this.dancesService.CreateAsync(input.Name, input.Description, user.Id, imageUrl, latinName, input.FolkloreArea, input.VideoUrl);

            return(this.RedirectToAction("ByName", new { name = latinName }));
        }
Пример #22
0
        public async Task <IActionResult> Edit(DanceEditViewModel danceToEdit)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var imageUrl = string.Empty;

            if (danceToEdit.Picture != null)
            {
                imageUrl = await CloudinaryExtension.UploadSingleAsync(this.cloudinary, danceToEdit.Picture);
            }

            string latinName = Transliteration.CyrillicToLatin(danceToEdit.Name, Language.Bulgarian);

            latinName = latinName.Replace(' ', '-');

            await this.dancesService.EditAsync(danceToEdit.Name, danceToEdit.Description, user.Id, imageUrl, latinName, danceToEdit.FolkloreArea, danceToEdit.VideoUrl, danceToEdit.Id);

            return(this.RedirectToAction("ByName", new { name = latinName }));
        }
        public async Task <IActionResult> UpdateProfile(UserProfileInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            if (input.ProfilePicture != null)
            {
                var imageInfo = await CloudinaryExtension.UploadImageAsync(this.cloudinary, input.ProfilePicture);

                await this.userService.UpdateProfile(input, imageInfo);
            }
            else
            {
                await this.userService.UpdateProfile(input);
            }

            return(this.RedirectToAction(nameof(this.Profile), new { username = "******" }));
        }
Пример #24
0
        public async Task EditCar(CarDetailsEditViewModel input)
        {
            var carToEdit = this.carRepository
                            .All()
                            .FirstOrDefault(c => c.Id == input.Id);

            if (input.MainImage != null)
            {
                var carMainImageUrl = await CloudinaryExtension.UploadFileAsync(this.cloudinary, input.MainImage);

                carToEdit.MainImageUrl = carMainImageUrl;
            }

            carToEdit.Model      = input.Model;
            carToEdit.Year       = input.Year;
            carToEdit.Horsepower = input.Horsepower;
            carToEdit.Torque     = input.Torque;
            carToEdit.Weight     = input.Weight;
            carToEdit.TopSpeed   = input.TopSpeed;

            await this.carRepository.SaveChangesAsync();
        }
Пример #25
0
        public async Task EditPost(string userId, EditPostInputModel input)
        {
            var postToEdit = this.posts
                             .All()
                             .FirstOrDefault(p => p.Id == input.Id);

            var postImageUrls = new List <string>();

            if (input.Images != null)
            {
                var postImagesUrls = await CloudinaryExtension.UploadAsync(this.cloudinary, input.Images);

                foreach (var url in postImagesUrls)
                {
                    postImageUrls.Add(url);
                }

                var postImage = this.postImages.All().FirstOrDefault(p => p.PostId == postToEdit.Id);
                postImage.ImageUrl = postImageUrls[0];
            }

            postToEdit.Description = input.Description;
            await this.posts.SaveChangesAsync();
        }
Пример #26
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl           = returnUrl ?? this.Url.Content("~/");
            this.ExternalLogins = (await this.signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (this.ModelState.IsValid)
            {
                var imageUri = await CloudinaryExtension.UploadImageAsync(this.cloudinary, this.Input.ProfileImage);

                if (imageUri == string.Empty)
                {
                    return(this.Page());
                }
                var user = new ApplicationUser {
                    UserName     = this.Input.UserName,
                    Email        = this.Input.Email,
                    FullName     = this.Input.FullName,
                    ProfileImage = imageUri.Replace(GlobalConstants.CloudinaryUploadDir, string.Empty),
                };
                var result = await this.userManager.CreateAsync(user, this.Input.Password);

                var addUserToRoleResult = await this.userManager.AddToRoleAsync(user, GlobalConstants.UserRoleName);


                if (result.Succeeded && addUserToRoleResult.Succeeded)
                {
                    this.logger.LogInformation("User created a new account with password.");
                    this.logger.LogInformation("User added to users role.");

                    if (this.Input.IsCompany)
                    {
                        var addUserToRoleCompanyResult = await this.userManager.AddToRoleAsync(user, GlobalConstants.CompanyRoleName);

                        if (addUserToRoleCompanyResult.Succeeded)
                        {
                            this.logger.LogInformation("User added to companies role.");
                            returnUrl = "/Companies/Add";
                        }
                    }

                    var code = await this.userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = this.Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code },
                        protocol: this.Request.Scheme);

                    await this.emailSender.SendEmailAsync(this.Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (this.userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(this.RedirectToPage("RegisterConfirmation", new { email = this.Input.Email }));
                    }
                    else
                    {
                        await this.signInManager.SignInAsync(user, isPersistent : false);

                        return(this.LocalRedirect(returnUrl));
                    }
                }

                foreach (var error in result.Errors)
                {
                    this.ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(this.Page());
        }
Пример #27
0
        public async Task <IActionResult> Upload(ICollection <IFormFile> files)
        {
            var result = await CloudinaryExtension.UploadAsync(cloudinary, files);

            return(View());
        }
Пример #28
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl           = returnUrl ?? this.Url.Content("~/");
            this.ExternalLogins = (await this.signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (this.ModelState.IsValid)
            {
                var avatarUrl = "https://res.cloudinary.com/sharwinchester/image/upload/v1587592729/Administrative/avatar_pnsyjm.png";

                if (this.File != null)
                {
                    avatarUrl = await CloudinaryExtension.UploadSingleAsync(this.cloudinary, this.File);
                }

                var user = new ApplicationUser
                {
                    UserName    = this.Input.Username,
                    Email       = this.Input.Email,
                    Description = this.Input.Description,
                    AvatarUrl   = avatarUrl,
                };

                var result = await this.userManager.CreateAsync(user, this.Input.Password);

                if (result.Succeeded)
                {
                    this.logger.LogInformation("User created a new account with password.");
                    await this.userManager.AddToRoleAsync(user, GlobalConstants.UserRoleName);

                    var code = await this.userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = this.Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code },
                        protocol: this.Request.Scheme);

                    await this.emailSender.SendEmailAsync(this.Input.Email, "Confirm your email",
                                                          $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (this.userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(this.RedirectToPage("RegisterConfirmation", new { email = this.Input.Email }));
                    }
                    else
                    {
                        await this.signInManager.SignInAsync(user, isPersistent : false);

                        return(this.LocalRedirect(returnUrl));
                    }
                }

                foreach (var error in result.Errors)
                {
                    this.ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(this.Page());
        }
Пример #29
0
        private async Task <string> DeleteImageFromCloudinaryAsync(string imagePath)
        {
            var cloudinaryPublicId = StringManipulations.GetNameFromUriWithoutExtension(imagePath);

            return(await CloudinaryExtension.DeleteImageImageAsync(this.cloudinary, cloudinaryPublicId));
        }