/// <summary> /// Gets a user for the web api based on the username provided. This is after determining if the user has valid payment status and updating the user in the database. /// </summary> /// <returns> /// User in the form of web api model /// </returns> /// <param name="username">Username of the user trying to access their info in the database.</param> public UserApiModel GetUser(string username) { try { // Gets a user from the DAL var user = _db.GetUserDb(username); // Sends a request for a list of invoices from Visma var invoiceList = GetInvoiceListFromVisma(); // Determines the payment status of the user trying to access their information from the database var paymentStatus = DeterminePaymentStatus(user, invoiceList); // Alters the user from database model to the web api model var outUser = new UserApiModel() { Username = user.Username, Name = user.Name, ValidPayment = user.ValidPayment, Membership = user.Membership }; // Updates the payment status of the user in the database _db.UpdatePaymentDetails(user, paymentStatus); return(outUser); } 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, UserApiModel GetUser(string username)"); return(null); } }
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)); }