public virtual IActionResult CreateBook([FromQuery] string name, [FromQuery] int?ownerId) { Book book = new Book(); book.Name = name; book.OwnerId = ownerId; context.Books.Add(book); context.SaveChanges(); return(new ObjectResult(true)); }
public virtual IActionResult CreateUser([FromQuery] string name, [FromQuery] string password) { if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(password)) { User user = new User(); user.Name = name; user.RoleId = 3; context.Users.Add(user); context.SaveChanges(); string query = $"UPDATE users SET password = '******' WHERE id = {user.Id.Value}"; context.Database.ExecuteSqlCommand(query); return(new ObjectResult(user.Id)); } return(new ObjectResult(null)); }