示例#1
0
        public HttpResponseMessage EditPassword([FromBody] User value)
        {
            if (ModelState.IsValid)
            {
                return((LogicUser.UpdatePassword(value)) ?
                       new HttpResponseMessage(HttpStatusCode.OK) :
                       new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new ObjectContent <String>("Can not update in DB", new JsonMediaTypeFormatter())
                });
            }
            ;

            List <string> ErrorList = new List <string>();

            //if the code reached this part - the user is not valid
            foreach (var item in ModelState.Values)
            {
                foreach (var err in item.Errors)
                {
                    ErrorList.Add(err.ErrorMessage);
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new ObjectContent <List <string> >(ErrorList, new JsonMediaTypeFormatter())
            });
        }