public ActionResult DeleteAccount(int id) { try { if (id != 0) { PortfolioContentController controller = new PortfolioContentController(_context); if (controller.DeletePortfolio(id)) { // Searching right user with ID var user = _context.Users.Find(id); _context.Remove(user); _context.SaveChanges(); } } return(Ok("Account and all content has deleted succesfully!")); } catch (Exception ex) { return(BadRequest("Problem detected while deleting user. Error message: " + ex.InnerException)); } finally { _context.Dispose(); } }
public ActionResult AddNewUser([FromBody] Users newUser) { try { _context.Users.Add(newUser); // Add a SAS token and the portfolio content with default values to a new user if (_context.SaveChanges() > 0) { AddSasToUser(_context, newUser.Username); PortfolioContentController controller = new PortfolioContentController(_context); controller.AddDefaultContent(newUser.Username); controller.AddDefaultEmails(newUser.Username); } return(Ok("New user has created and the portfolio content with default values has added!")); } catch (Exception ex) { return(BadRequest("Problem detected while adding a new user. Error message: " + ex.Message)); } finally { _context.Dispose(); } }