Exemple #1
0
        /// <summary>
        /// Images the upload.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="email">The email.</param>
        /// <returns>
        /// return the image url.
        /// </returns>
        /// <exception cref="System.Exception">
        /// throw exception
        /// </exception>
        public async Task <string> ImageUpload(IFormFile file, string userId)
        {
            try
            {
                ////create object of the cloudinaryImage class
                CloudinaryImage cloudinary = new CloudinaryImage();

                ////Cloudinary UploadImageCloudinary method call
                var uploadUrl = cloudinary.UploadImageCloudinary(file);

                ////Query to get the note data from database
                var data = this.context.ApplicationUser.Where(applicationUser => applicationUser.Id == userId).FirstOrDefault();

                ////update the ImageUrl to database Notes table
                data.Image = uploadUrl;

                ////Update save changes in database table
                int result = await this.context.SaveChangesAsync();

                ////if result is greater than zero then return the update result
                if (result > 0)
                {
                    return(data.Image);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public async Task <string> ImageUploadWhileCratingNote(IFormFile file)
        {
            try
            {
                ////create object of the cloudinaryImage class
                CloudinaryImage cloudinary = new CloudinaryImage();

                ////Cloudinary UploadImageCloudinary method call
                var uploadUrl = cloudinary.UploadImageCloudinary(file);

                ////Update save changes in dabase table
                int result = await this.context.SaveChangesAsync();

                ////if result is grater than zero then return the update result
                if (!uploadUrl.Equals(null))
                {
                    return(uploadUrl);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public async Task <int> WriteToDbAsync(string uploaderId, string pictureUrl, string pictureThumbnailUrl,
                                               string picPublicId, DateTime uploadedOn, long picLength)
        {
            var image = new CloudinaryImage
            {
                UploaderId          = uploaderId,
                PictureUrl          = pictureUrl,
                PictureThumbnailUrl = pictureThumbnailUrl,
                PicturePublicId     = picPublicId,
                UploadedOn          = uploadedOn,
                Length = picLength
            };

            await this.db.CloudinaryImages.AddAsync(image);

            await this.db.SaveChangesAsync();

            return(image.Id);
        }