示例#1
0
        public IActionResult AddUser([FromBody] Users user)
        {
            try
            {
                if (user == null)
                {
                    return(BadRequest("User object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }
                _context.Add(user);
                return(CreatedAtRoute("AddUser", new { id = user.UserId }, user));
            }
            catch (Exception ex)
            {
                Console.Write($"Something went wrong inside the AddUser action: {ex}");
                return(StatusCode(500, "Internal Server Error"));
            }
        }
        public IActionResult AddContact([FromBody] Contacts contact)
        {
            try
            {
                if (contact == null)
                {
                    return(BadRequest("Owner object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }
                _context.Add(contact);
                return(CreatedAtRoute("ContactById", new { id = contact.ContactId }, contact));
            }
            catch (Exception ex)
            {
                Console.Write($"Something went wrong inside the CreateOwner action: {ex}");
                return(StatusCode(500, "Internal Server Error"));
            }
        }