/// <summary> /// this function will activate the trial subscription for an account /// </summary> /// <param name="user">the user for which the trial will activate</param> /// <returns>the state of the command</returns> public void ActivateTrialSubscription(User user) { //we prepare the action log #region Action Log //set the action String Action = "Activat abonamentul de trial pentru utilizatorul " + user.Email; //retrieve the IP String IP = IPFunctions.GetWANIp(); //then format the command String Command = String.Format("UPDATE users.abonamente_utilizatori " + "SET abonament_id = {0}" + " ultima_plata = {1} " + "WHERE utilizator_id = {2} AND abonament_id = {3}", (Int64)Settings.Subscriptions.SubscriptionSettings.Subscriptions.ActiveTrialSubscription, DateTime.Now, user.ID, (Int64)Settings.Subscriptions.SubscriptionSettings.Subscriptions.InactiveSubscription ); #endregion //then we will update the user subscription base.AbonamenteUtilizatori.Where(element => element.UtilizatorId == user.ID && element.AbonamentId == (Int64)Settings.Subscriptions.SubscriptionSettings.Subscriptions.InactiveSubscription) .ToList() .ForEach(element => { element.AbonamentId = (Int64)Settings.Subscriptions.SubscriptionSettings.Subscriptions.ActiveTrialSubscription; element.UltimaPlata = DateTime.Now; }); //and log the action base.LogActiuni.Add(ActionLog.LogAction(Action, IP, Command)); base.SaveChanges(); }
/// <summary> /// this function will register a new user in the database and then return it /// </summary> /// <param name="registerController">the register controller for the new user</param> /// <returns>the newly added user</returns> public User RegisterUser(RegisterController registerController) { //we set the log action #region LogAction //the action for the log String Action = "A fost inregistrat un nou utilizator la adresa de email: " + registerController.Email; //First we format the command to register String Command = String.Format("INSERT INTO users.utilizatori(nume_utilizator,email,parola,nume,prenume) " + "VALUES({0},{1},{2},{3},{4}) RETURNING *", registerController.Username, registerController.Email, registerController.Password, registerController.Surname, registerController.Name ); //then we will create a new ipFunctions for the httpContextAccessor String IP = IPFunctions.GetWANIp(); #endregion //and generate a new user in order to keep the link active Utilizatori utilizatorNou = new Utilizatori() { NumeUtilizator = registerController.Username, Email = registerController.Email, Parola = registerController.Password, Nume = registerController.Surname, Prenume = registerController.Name }; //add the new user to the base controller base.Utilizatori.Add(utilizatorNou); //log the action base.LogActiuni.Add(ActionLog.LogAction(Action, IP, Command)); //save the changes base.SaveChanges(); //and return a new id return(new User() { ID = utilizatorNou.Id, Username = utilizatorNou.NumeUtilizator, Email = utilizatorNou.Email, Name = utilizatorNou.Prenume, Surname = utilizatorNou.Nume }); }
/// <summary> /// this is the main function for updating the password /// </summary> /// <param name="user">the user for which we will update the password</param> /// <param name="resetPasswordController">the password</param> /// <returns>the state of the query</returns> public Boolean UpdatePassword(User user, ResetPasswordController resetPasswordController) { #region LogAction //the main Action for the log String Action = String.Format("Sa actualizat parola utilizatorului cu emailul {0}", user.Email); //the main command format for the log String Command = String.Format("UPDATE users.utilizatori SET parola = {0} WHERE id = {1}", resetPasswordController.Password, user.ID); //then we will create a new ipFunctions to get the WanIP String IP = IPFunctions.GetWANIp(); #endregion Utilizatori utilizator = base.Utilizatori.Find(user.ID); utilizator.Parola = resetPasswordController.Password; base.Update(utilizator); base.LogActiuni.Add(ActionLog.LogAction(Action, IP, Command)); try { base.SaveChanges(); return(true); } catch { return(false); } }
/// <summary> /// this function generates the initial subscription for an account /// </summary> /// <param name="user">the newly created user</param> /// <returns>the state of the command</returns> public Boolean GenerateInactiveSubscription(User user) { #region Action Log String Action = "Initializat abonamentul inactiv pentru utilizatorul " + user.Email; String Command = String.Format("INSERT INTO users.abonamente_utilizatori(utilizator_id, abonament_id) " + "VALUES({0},{1})", user.ID, (Int64)Settings.Subscriptions.SubscriptionSettings.Subscriptions.InactiveSubscription); String IP = IPFunctions.GetWANIp(); #endregion //we will add a new item to the list base.AbonamenteUtilizatori.Add(new AbonamenteUtilizatori() { UtilizatorId = user.ID, AbonamentId = (Int64)Settings.Subscriptions.SubscriptionSettings.Subscriptions.InactiveSubscription }); //and log the action base.LogActiuni.Add(ActionLog.LogAction(Action, IP, Command)); //and save the changes to the database try { base.SaveChanges(); return(true); } catch { return(false); } }