Ejemplo n.º 1
0
        public IActionResult Post([FromBody] User user)
        {
            try
            {
                if (user == null || !ModelState.IsValid)
                {
                    return(BadRequest());
                }
                bool itemExists = _context.Users.Any(u => u.Id == user.Id);

                if (itemExists)
                {
                    return(StatusCode(StatusCodes.Status409Conflict, "user already exists"));
                }

                _context.Add(user);
                _context.SaveChanges();
            }
            catch (Exception)
            {
                return(BadRequest("Could not create item"));
            }

            return(Ok(user));
        }
Ejemplo n.º 2
0
        public IActionResult Post([FromBody] MiriotConfiguration config)
        {
            try
            {
                if (config == null || !ModelState.IsValid)
                {
                    return(BadRequest());
                }
                bool itemExists = _context.Configurations.Any(c => c.Id == config.Id);
                if (itemExists)
                {
                    return(StatusCode(StatusCodes.Status409Conflict, "config already exists"));
                }

                _context.Add(config);
                _context.SaveChanges();
            }
            catch (Exception)
            {
                return(BadRequest("Could not create item"));
            }

            return(Ok(config));
        }