Exemple #1
0
        public string GetUser([FromBody] CRUDRequest req)
        {
            bool         IsAccessTokenExpired = false;
            ResponseData Resp = new ResponseData();

            IsAccessTokenExpired = MySQLDapperQueries.IsAccessTokenExpired(req.accesstoken);
            if (IsAccessTokenExpired)
            {
                Resp = new ResponseData
                {
                    Code    = "600",
                    Message = "Access Token Expired",
                    Data    = null
                };
            }
            else
            {
                Resp = new ResponseData
                {
                    Code    = "200",
                    Message = "OK",
                    Data    = MySQLDapperQueries.GetUserByID(req.id)
                };
            }
            return(JsonConvert.SerializeObject(Resp, Formatting.None));
        }
Exemple #2
0
        public string DeleteUser([FromBody] CRUDRequest req)
        {
            bool         IsAccessTokenExpired = false;
            ResponseData Resp = new ResponseData();

            IsAccessTokenExpired = MySQLDapperQueries.IsAccessTokenExpired(req.accesstoken);
            if (IsAccessTokenExpired)
            {
                Resp = new ResponseData
                {
                    Code    = "600",
                    Message = "Access Token Expired",
                    Data    = null
                };
            }
            else
            {
                string response = MySQLDapperQueries.DeleteUser(req.id);
                if (response == "ok")
                {
                    Resp = new ResponseData
                    {
                        Code    = "200",
                        Message = "User Deleted Sucessfully",
                        Data    = null
                    };
                }
                else
                {
                    Resp = new ResponseData
                    {
                        Code    = "502",
                        Message = response,
                        Data    = null
                    };
                }
            }
            return(JsonConvert.SerializeObject(Resp, Formatting.None));
        }
Exemple #3
0
        public string UpdateUser([FromBody] CRUDRequest req)
        {
            ResponseData Resp = new ResponseData();

            if (!this.ModelState.IsValid)
            {
                Resp = new ResponseData
                {
                    Code    = "404",
                    Message = "Invalid Parameters",
                    Data    = null
                };
                return(JsonConvert.SerializeObject(Resp, Formatting.None));
            }
            bool IsAccessTokenExpired = false;

            IsAccessTokenExpired = MySQLDapperQueries.IsAccessTokenExpired(req.accesstoken);
            if (IsAccessTokenExpired)
            {
                Resp = new ResponseData
                {
                    Code    = "600",
                    Message = "Access Token Expired",
                    Data    = null
                };
            }
            else
            {
                try
                {
                    string salt           = "";
                    string hashedpassword = "";
                    if (!String.IsNullOrEmpty(req.password.Trim()))
                    {
                        salt           = Authentication.GenerateRandomSalt(15);
                        hashedpassword = Authentication.GenerateHashedPWD(req.password, salt);
                    }
                    string response = MySQLDapperQueries.UpdateUser(req.id, req.username, hashedpassword, salt, req.name, req.email);
                    if (response == "ok")
                    {
                        Resp = new ResponseData
                        {
                            Code    = "200",
                            Message = "User Created",
                            Data    = null
                        };
                    }
                    else
                    {
                        Resp = new ResponseData
                        {
                            Code    = "502",
                            Message = response,
                            Data    = null
                        };
                    }
                }
                catch
                {
                    Resp = new ResponseData
                    {
                        Code    = "502",
                        Message = "An Error Occured",
                        Data    = null
                    };
                }
            }
            return(JsonConvert.SerializeObject(Resp, Formatting.None));
        }