public IActionResult Add(ProductCategory category) { //Validate category data if (category.Name == "") { return(BadRequest(category)); } _context.Categories.Add(category); _context.SaveChanges(); return(CreatedAtAction(nameof(GetCategory), new { id = category.Id }, category)); }
public IActionResult Add(Message message) { if (message.Title == null) { return(NotFound()); } if (message.Title == "") { return(BadRequest(message)); } _context.Messages.Add(message); _context.SaveChanges(); return(CreatedAtAction(nameof(GetMessage), new { id = message.Id }, message)); }
public ActionResult <UserModel> Create(UserModel user) { var newUser = new UserModel(user.Username, user.Password); newUser.AccountType = user.AccountType; _context.Add(newUser); _context.SaveChanges(); return(CreatedAtAction(nameof(Login), new { id = newUser.Id }, newUser)); }
public IActionResult Add(Product product) { ProductCategory ProductCategory = _context.Categories.SingleOrDefault(c => c.Id == product.CategoryId); product.Category = ProductCategory; if (product.Name == null) { return(NotFound()); } if (product.Name == "") { return(BadRequest(product)); } _context.Products.Add(product); _context.SaveChanges(); return(CreatedAtAction(nameof(GetProduct), new { id = product.Id }, product)); }
public UserModel Create(UserModel user, string password) { if (string.IsNullOrWhiteSpace(password)) { throw new AppException("Password can't be empty"); } if (_context.Users.Any(u => u.Username == user.Username)) { throw new AppException("Username already taken"); } _context.Users.Add(user); _context.SaveChanges(); return(user); }
public UserModel Create(UserModel user, string password) { if (string.IsNullOrWhiteSpace(password)) { throw new AppException("Password can't be empty"); } if (_context.Users.Any(u => u.Username == user.Username)) { throw new AppException("Username already taken"); } byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.Password = passwordHash; user.StoredSalt = passwordSalt; _context.Users.Add(user); _context.SaveChanges(); return(user); }