/// <summary>
        /// This method will get called to upload image to cloudinary
        /// and also store information about the image to DB.
        /// Also to create images on db.
        /// </summary>
        /// <param name="imageModel"></param>
        /// <returns>
        /// Returns a tuple of the method response and a descriptive message.
        /// </returns>
        public async Task <(object response, string message)> UploadImageCloudinary(ImageModel imageModel)
        {
            if (imageModel == null)
            {
                return(response : null, message : $"Image upload Failed, check passed params.");
            }
            var userCtx = _httpContextAccessor.HttpContext.User.Identity.Name;
            var usr     = await _userrepo.FirstOrDefault(t => t.Username == userCtx);

            //Cloud Acct
            var apiKey     = configuration["CloudinaryData:ApiKey"];
            var apiSecret  = configuration["CloudinaryData:ApiSecret"];
            var cloudAlias = configuration["CloudinaryData:CloudAlias"];
            // Category is stored in lower case
            var checkCat = await _catrepo.FirstOrDefault(c => c.CategoryName == imageModel.CategoryName.ToLowerInvariant());

            if (checkCat == null)
            {
                return(response : null, message : $"{imageModel.CategoryName} doesnt exists");
            }

            var imgExist = _imgrepo.FirstOrDefault(t => t.PhotoName == imageModel.PhotoName.ToLowerInvariant());

            //Call upload method to push to Cloudinary
            var(url, img, msg) = await ProcessUpload.UploadToTheCloud(imageModel, apiKey, apiSecret, cloudAlias, _env);

            if (img == null || url == null)
            {
                return(response : null, message : msg);
            }

            var tags = imageModel.Tags.ToLowerInvariant();
            // save url to db
            var newPhoto = new ImageModel().CreatePhoto(imageModel);

            newPhoto.FilePath     = url;
            newPhoto.UserId       = usr.ID;
            newPhoto.CategoryId   = checkCat.ID;
            newPhoto.CategoryName = checkCat.CategoryName;
            newPhoto.PhotoName    = imageModel.PhotoName.ToLowerInvariant();
            newPhoto.Tags         = tags;

            // Add the image to category and save to db

            try
            {
                await _imgrepo.Insert(newPhoto);
            }
            catch (DbUpdateException ex)
            {
                log.LogError($"=> {ex}");
                return(response : null, message : $"{ex.Message}");
            }

            return(response : newPhoto, message : msg);
        }
 public bool Update(ProcessUpload item)
 {
     using (IDbConnection db = new SqlConnection(ConnectionString))
     {
         Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
         if (db.State == ConnectionState.Closed)
         {
             db.Open();
         }
         int result = db.Execute("UPDATE PROCESS SET NAME = @Name, ID_DEPARTMENT = @IdDepartment WHERE ID = @Id", item);
         return(result > 0);
     }
 }
 public bool Insert(ProcessUpload item)
 {
     using (IDbConnection db = new SqlConnection(ConnectionString))
     {
         Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
         if (db.State == ConnectionState.Closed)
         {
             db.Open();
         }
         int result = db.Execute("INSERT INTO PROCESS(NAME, ID_DEPARTMENT) VALUES (@Name, @IdDepartment)", item);
         return(result > 0);
     }
 }