Beispiel #1
0
        public async Task <HttpStatusCode> DeleteWhere(object list)
        {
            try
            {
                if (list == null)
                {
                    return(HttpStatusCode.UnprocessableEntity);
                }

                var parameterSqlString             = "";
                Dictionary <string, object> values = PropertyValuesDict(list);

                foreach (KeyValuePair <string, object> entry in values)
                {
                    parameterSqlString = parameterSqlString + entry.Key + "= @" + entry.Key + " AND ";
                }

                string sql = $@"DELETE FROM `{DbName}` WHERE {parameterSqlString} DeactivatedOn IS NULL";

                using (var con = new MySqlConnection(GetConnection()))
                    await con.ExecuteAsync(sql, list);
                return(HttpStatusCode.OK);
            }
            catch (MySqlException e)
            {
                logger.LogError(e, e.Message);
                return(MySqlExpcetionMapper.ExceptionHttpCode(e));
            }
            catch (Exception e)
            {
                logger.LogError(e, e.Message);
                return(HttpStatusCode.InternalServerError);
            }
        }
Beispiel #2
0
        public async Task <HttpStatusCode> Deactivate(T obj)
        {
            try
            {
                if (obj.DeactivatedOn == null)
                {
                    obj.DeactivatedOn = DateTime.Now;
                }

                string sql = $@"
                    UPDATE `{DbName}` 
					SET
					    `DeactivatedOn` = @DeactivatedOn
                    WHERE
					    `Id` = @Id"                    ;

                using (var con = new MySqlConnection(GetConnection()))
                    await con.ExecuteAsync(sql, obj);
                return(HttpStatusCode.OK);
            }
            catch (MySqlException e)
            {
                return(MySqlExpcetionMapper.ExceptionHttpCode(e));
            }
        }
Beispiel #3
0
        public async Task <HttpStatusCode> Update(T obj, string updateFields = null)
        {
            try
            {
                string sql = UpdateQuery <T>(updateFields);

                using (var con = new MySqlConnection(GetConnection()))
                    await con.ExecuteAsync(sql, obj);
                return(HttpStatusCode.OK);
            }
            catch (MySqlException e)
            {
                logger.LogError(e, e.Message);
                return(MySqlExpcetionMapper.ExceptionHttpCode(e));
            }
        }
Beispiel #4
0
 public async Task <HttpStatusCode> Add(T obj)
 {
     try
     {
         string sql = InsertQuery <T>();
         using (var con = new MySqlConnection(GetConnection()))
             await con.ExecuteAsync(sql, obj);
         return(HttpStatusCode.OK);
     }
     catch (MySqlException e)
     {
         logger.LogError(e, e.Message);
         return(MySqlExpcetionMapper.ExceptionHttpCode(e));
     }
     catch (Exception e)
     {
         logger.LogError(e, e.Message);
         return(HttpStatusCode.InternalServerError);
     }
 }
Beispiel #5
0
        public async Task <HttpStatusCode> Delete(T obj)
        {
            try
            {
                string sql = $@"DELETE FROM `{DbName}` WHERE `Id` = @Id";

                using (var con = new MySqlConnection(GetConnection()))
                    await con.ExecuteAsync(sql, obj);
                return(HttpStatusCode.OK);
            }
            catch (MySqlException e)
            {
                logger.LogError(e, e.Message);
                return(MySqlExpcetionMapper.ExceptionHttpCode(e));
            }
            catch (Exception e)
            {
                logger.LogError(e, e.Message);
                return(HttpStatusCode.InternalServerError);
            }
        }