public string RegisterUser(UserViewModel innUser) { // Gets the user from the database var user = _db.GetUserDb(innUser.Username); // Returns an error message if the user does not have a registered membership in the database and therefore Visma eAccounting if (user == null) { return("Det er ingen aktive medlemmer med den eposten"); } // If a user is already an active user the registration is not valid and an error message is returned if (user.ActiveUser) { return("En bruker er allerede registrert med den eposten"); } return(_db.RegisterUser(user, innUser.Password)); }
/// <summary> /// Sends a request to the DAL to register a password to an existing member from the mobile application. This is after determining if the member has a user in the database as well as valid payment. /// </summary> /// <returns> /// <c>string</c> containing "Success" if successful or an error message describing what went wrong. /// </returns> /// <para>Users are added from Vismas servers so a user needs to be a member before registering in the mobile app. The user is updated in the database after registration. </para> /// <param name="innUser">A user with username and password to be registered.</param> public string RegisterUser(UserViewModel innUser) { try { // Gets the user from the database var user = _db.GetUserDb(innUser.Username); // Returns an error message if the user does not have a registered membership in the database and therefore Visma eAccounting if (user == null) { return("Det er ingen aktive medlemmer med den eposten"); } // If a user is already an active user the registration is not valid and an error message is returned if (user.ActiveUser) { return("En bruker er allerede registrert med den eposten"); } // Sends a request for a list of invoices from Visma var invoiceList = GetInvoiceListFromVisma(); // Determines the payment status of the user from the database var paymentStatus = DeterminePaymentStatus(user, invoiceList); // Sets the new payment status for the user before registration. user.ValidPayment = paymentStatus; // Registers the user return(_db.RegisterUser(user, innUser.Password)); } catch (Exception e) { // Creates a new error filer object var errorLog = new ErrorFiler(); // Logs the error to the error log, with the name of the exception and where it occured errorLog.WriteError(e.GetType().FullName, "NasBLL, string RegisterUser(UserViewModel innUser)"); return("Det har oppstått en feil, vennligst prøv igjen senere"); } }