Exemplo n.º 1
0
        public IActionResult RemoveUser([FromBody] RemoveUserJson jsonData)
        {
            try
            {
                User user = db.SetStatus(jsonData.RemoveUser.Id, "Deleted");

                if (user == null)
                {
                    throw new Exception("User not found");
                }

                SuccessRemoveUserJson successRemoveUser = new SuccessRemoveUserJson()
                {
                    Msg     = "User was removed",
                    Success = true,
                    User    = user
                };

                return(Ok(successRemoveUser));
            }
            catch (Exception e)
            {
                NotSuccessRemoveUserJson notSuccessRemoveUser = new NotSuccessRemoveUserJson()
                {
                    ErrorId = 2,
                    Msg     = e.Message,
                    Success = false
                };

                return(BadRequest(notSuccessRemoveUser));
            }
        }
Exemplo n.º 2
0
        public IActionResult SetStatus([FromForm] IFormCollection formData)
        {
            try
            {
                string id     = formData["Id"];
                string status = formData["NewStatus"];

                User user = db.SetStatus(int.Parse(id), status);

                if (user == null)
                {
                    throw new Exception("User not found");
                }

                Dictionary <string, StringValues> formResponse = new Dictionary <string, StringValues>
                {
                    { "Id", user.Id.ToString() },
                    { "Name", user.Name },
                    { "Status", user.Status }
                };

                IFormCollection response = new FormCollection(formResponse);

                return(Ok(JsonConvert.SerializeObject(response)));
            }
            catch (Exception e)
            {
                NotSuccessRemoveUserJson notSuccessRemoveUser = new NotSuccessRemoveUserJson()
                {
                    ErrorId = 2,
                    Msg     = e.Message,
                    Success = false
                };
                return(BadRequest(notSuccessRemoveUser));
            }
        }