public async Task <IActionResult> Update(int id, [FromBody] UserViewModel user)
        {
            if (user == null || user.Id != id)
            {
                return(BadRequest());
            }

            if (await _userServiceAsync.Update(user))
            {
                return(Accepted(user));
            }
            else
            {
                return(StatusCode(304));     //Not Modified
            }
        }
        public async Task <ActionResult <object> > PutAsync(int id, [FromBody] UserViewModel user)
        {
            if (user == null || user.Id != id)
            {
                var toSerialize = new MessageHelpers <UserViewModel>()
                {
                    Status = 404,
                    Data   = null
                };
                return(JsonConvert.SerializeObject(toSerialize));
            }
            else
            {
                try
                {
                    int retVal = await _userServiceAsync.Update(user);

                    if (retVal == 0 && retVal > 0)
                    {
                        var toSerialize = new MessageHelpers <UserViewModel>()
                        {
                            Status = 200,
                            Data   = null
                        };
                        return(JsonConvert.SerializeObject(toSerialize));
                    }
                    else
                    {
                        var toSerialize = new MessageHelpers <UserViewModel>()
                        {
                            Status = 404,
                            Data   = null
                        };
                        return(JsonConvert.SerializeObject(toSerialize));
                    }
                }
                catch
                {
                    var toSerialize = new MessageHelpers <UserViewModel>()
                    {
                        Status = 502,
                        Data   = null
                    };
                    return(JsonConvert.SerializeObject(toSerialize));
                }
            }
        }
        public async Task <IActionResult> Update(int id, [FromBody] UserPassViewModel user)
        {
            int retVal = await _userServiceAsync.Update(user);

            if (retVal == 0)
            {
                return(StatusCode(304));  //Not Modified
            }
            else if (retVal == -1)
            {
                return(StatusCode(412, "DbUpdateConcurrencyException"));  //412 Precondition Failed  - concurrency
            }
            else
            {
                return(Accepted(user));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Update(Int64 id, [FromBody] UserViewModel user)
        {
            if (user == null || user.Id != id)
            {
                return(BadRequest());
            }

            var retVal = await _userServiceAsync.Update(user);

            if (retVal == 0)
            {
                return(StatusCode(304));  //Not Modified
            }
            else if (retVal == -1)
            {
                return(StatusCode(412, "DbUpdateConcurrencyException"));  //412 Precondition Failed  - concurrency
            }
            else
            {
                return(Accepted(user));
            }
        }