Ejemplo n.º 1
0
        public IActionResult PutUsers([FromRoute] int id, [FromBody] User.Models.User users)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != users.Id)
            {
                return(BadRequest());
            }

            _context.Entry(users).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UsersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public IActionResult PostUsers([FromBody] User.Models.User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            var _user = _context.Users.SingleOrDefault(m => m.UserName == user.UserName);

            try
            {
                if (user != null)
                {
                    if (_user == null)
                    {
                        _context.Users.Add(user);
                        _context.SaveChanges();
                    }
                    else
                    {
                        if (_user.UserName == user.UserName)
                        {
                            return(BadRequest("UserName " + user.UserName + " already exists"));
                        }
                    }
                }
                else
                {
                    return(BadRequest(new { message = "Error", info = "Bad Request" }));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = "Error", info = ex }));
            }


            return(Ok(user));
        }