public IHttpActionResult GetUserAccountByName(AccountNameDTO accountName) // Gets UserAccount entity from DB with accountname; accountName is found in json body, not the url! { UserAccountsManager umgr = new UserAccountsManager(); UserAccounts user = new UserAccounts(); user = umgr.GetUserAccountByName(accountName.AccountName); // function thats gets user entity from DB if (user is null) // if user entity is null { TextResult failedToFindAccount = new TextResult("Failed to find account", msg); return(failedToFindAccount); } return(Ok(user)); }
public IHttpActionResult DeleteUserAccounts(AccountNameDTO accName) { UserAccountsManager umgr = new UserAccountsManager(); CustomerManager cmgr = new CustomerManager(); var user = umgr.GetUserAccountByName(accName.AccountName); var customer = cmgr.GetCustomerEntityFromId(user.customerId); try { db.UserAccounts.Remove(user); db.Customers.Remove(customer); db.SaveChanges(); } catch { TextResult httpResponse = new TextResult("Failed to delete account!", msg); // Http response return(httpResponse); } return(Ok()); }