// This function will be used to execute CUD(CRUD) operation of parameterized commands public bool ExecuteNonQuery(string commandName, CommandType cmdType, SqlParameter[] pars) { int result = 0; using (RentEntities context = new RentEntities()) { var cc = context.Database.Connection.ConnectionString; using (SqlConnection con = new SqlConnection(cc)) { using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = cmdType; cmd.CommandText = commandName; cmd.Parameters.AddRange(pars); try { if (con.State != ConnectionState.Open) { con.Open(); } result = cmd.ExecuteNonQuery(); } catch (Exception exception) { throw; } } } } return(result > 0); }
public static string AccessCode() { using (Entities.RentEntities context = new RentEntities()) { var length = 6; var r = ""; const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; StringBuilder res = new StringBuilder(); Random rnd = new Random(); while (0 < length--) { res.Append(valid[rnd.Next(valid.Length)]); } r = res.ToString(); while (context.UsersAccesses.Any(x => x.AccessCode == r)) { length = 6; r = ""; res.Clear(); while (0 < length--) { res.Append(valid[rnd.Next(valid.Length)]); } r = res.ToString(); } return(r); } return(null); }
public static void Insert(Exception exception, int uid) { Rent.Entities.RentEntities context = new RentEntities(); repository = new GenericRepository <Entities.LogError>(context); Entities.LogError logError = new Entities.LogError(); logError.Created = DateTime.Now; logError.Modifed = null; logError.Message = exception.Message; logError.InnerMessage = null; logError.Uid = uid; repository.Insert(logError); }
public override string[] GetRolesForUser(string username) { using (Rent.Entities.RentEntities context = new RentEntities()) { var r = context.Users.Where(x => x.Name == username).FirstOrDefault(); if (r == null) { return new string[] {} } ; var obj = r.UsersRoles.FirstOrDefault().Role1.Name; return(new[] { obj }); } }
public void User_UserRoleUpdate(Entities.User obj) { using (var context = new RentEntities()) { var user = context.Users.SingleOrDefault(x => x.Uid == obj.Uid); var userRole = context.UsersRoles.SingleOrDefault(x => x.Uid == obj.Uid); context.Users.Remove(user); context.UsersRoles.Remove(userRole); context.Users.Add(user); context.UsersRoles.Add(userRole); //user.UsersRoles.Add(userRole); //userRole.Users.Add(user); context.SaveChanges(); } }
public bool Validate(Entities.User obj, string status) { bool b = true; using (Rent.Entities.RentEntities context = new RentEntities()) { switch (status) { case "update": b = context.Users.Any(x => x.Email == obj.Email.ToLower() && x.Active && x.Uid != obj.Uid); break; case "insert": b = context.Users.Any(x => x.Email == obj.Email.ToLower() && x.Active); break; } } return(b); }
// This function will be used to execute R(CRUD) operation of parameterless commands public DataTable ExecuteDataTable(string commandName, CommandType cmdType) { DataTable table = null; using (RentEntities context = new RentEntities()) { var cc = context.Database.Connection.ConnectionString; using (SqlConnection con = new SqlConnection(cc)) { using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = cmdType; cmd.CommandText = commandName; try { if (con.State != ConnectionState.Open) { con.Open(); } using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { table = new DataTable(); da.Fill(table); } } catch { throw; } } } } return(table); }
public LogEmail(RentEntities context) { repository = new GenericRepository <Entities.RentPaymentNoticeSendLog>(context); _ILogEmailrepository = new GenericRepository <Entities.LogEmail>(context); iSqlDbHelper = new SqlDbHelper(); }
public Roles(RentEntities context) { repository = new GenericRepository <Role1>(context); }
public UsersPassword(RentEntities context) { repository = new GenericRepository <Entities.UsersPassword>(context); }
public UserManager(RentEntities context) { repository = new GenericRepository <UsersManager>(context); }
public RentPaymentNoticeSendLog(RentEntities context) { repository = new GenericRepository <Entities.RentPaymentNoticeSendLog>(context); }
public User(RentEntities context) { repository = new GenericRepository <Entities.User>(context); }
public RentPayment(RentEntities context) { repository = new GenericRepository <Entities.RentPayment>(context); iSqlDbHelper = new SqlDbHelper(); }
public string ForgotPasswordEmail(Entities.User obj) { var r = ""; try { using (var context = new RentEntities()) { var objPassword = context.Users.FirstOrDefault(x => x.Email == obj.Email && x.Active); if (objPassword == null) { r = "Email was not found. Please try again."; return(r); } // password generate var newPassword = Rent.Common.Helper.Generator.Password(); // set userPassword object // call userPassword interface Business.Interfaces.IUserPassword iUserPassword = new UsersPassword(new RentEntities()); var objUsersPassword = iUserPassword.Select(objPassword.Uid); objUsersPassword.Password = newPassword; iUserPassword.Update(objUsersPassword); const string subject = "Rental Payment - New Password"; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("Hello " + objPassword.Name + ","); stringBuilder.Append("<p>Your temporary password is: </br> " + newPassword); stringBuilder.Append("</br></br>"); stringBuilder.Append("We encourage you to create a password you can easily remember. </br>"); stringBuilder.Append("You can login with your information here: " + Rent.Business.Properties.Settings.Default.Host + " to view your account."); stringBuilder.Append("</br> "); // send email var i = Rent.Common.Helper.Email.MlfusionSmtp(new MailAddress(obj.Email), subject, stringBuilder.ToString(), true); var j = Business.Services.LogEmail.Insert(stringBuilder, obj.Uid, obj.Email); // send text message if (obj.Phone != null) { foreach (var source in Rent.Common.Helper.Carriers.SelectMobileCarriers(obj.Phone)) { i = +Rent.Common.Helper.Email.MlfusionSmtp(new MailAddress(source), subject, stringBuilder.ToString(), false); // insert into LogEmail j = +Business.Services.LogEmail.Insert(stringBuilder, obj.Uid, source); } } r = i > 0 ? "Login credentials has been emailed to you." : "Sorry, the web service is down. Please try again later."; } } catch (Exception exception) { Business.Services.LogError.Insert(exception, 0); r = "Error: " + exception.Message; } return(r); }
public string RentPaymentEmail(int id) { var r = ""; var i = 0; var j = 0; try { using (var context = new RentEntities()) { var obj = context.RentPayments.FirstOrDefault(x => x.RentPaymentId == id); if (obj == null) { r = "Email was not found. Please try again."; return(r); } const string subject = "Rental Payment - Rental Payment Email"; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<p>Hello, " + obj.User.Name + "</br> "); stringBuilder.Append("Your rent payment was just posted. "); stringBuilder.Append("Please login with your credentials here: " + Rent.Business.Properties.Settings.Default.Host + Properties.Settings.Default.Login + " to view your payment."); stringBuilder.Append("</br>"); // send email and check if UsersNotification.Email = true if ((bool)obj.User.UsersNotifications.FirstOrDefault().Email) { i = Rent.Common.Helper.Email.MlfusionSmtp(new MailAddress(obj.User.Email), subject, stringBuilder.ToString(), true); j = Business.Services.RentPaymentNoticeSendLog.Insert(stringBuilder, obj, obj.User.Email); // insert into LogEmail Business.Services.LogEmail.Insert(stringBuilder, obj.Uid, obj.User.Email); } else { var sb = new StringBuilder(Notifications.EmailNotice + stringBuilder); // insert into LogEmail Business.Services.LogEmail.Insert(sb, obj.Uid, obj.User.Email); } // send text message if (obj.User.Phone != null) { foreach (var source in Rent.Common.Helper.Carriers.SelectMobileCarriers(obj.User.Phone)) { //check if UsersNotification.Phone = true if ((bool)obj.User.UsersNotifications.FirstOrDefault().Phone) { i = +Rent.Common.Helper.Email.MlfusionSmtp(new MailAddress(source), subject, stringBuilder.ToString(), false); j = +Business.Services.RentPaymentNoticeSendLog.Insert(stringBuilder, obj, source); // insert into LogEmail Business.Services.LogEmail.Insert(stringBuilder, obj.Uid, source); } else { var sb = new StringBuilder(Notifications.PhoneNotice + stringBuilder); // insert into LogEmail Business.Services.LogEmail.Insert(sb, obj.Uid, source); } } } if (i > 0) { if (j <= 0) { return(r = "Error occured on SQL end"); } } r = "Rent Payment email was sent to " + obj.User.Email + "; Email status -> " + obj.User.UsersNotifications.FirstOrDefault().Email + "; Phone -> " + obj.User.UsersNotifications.FirstOrDefault().Phone; } } catch (Exception exception) { Business.Services.LogError.Insert(exception, id); r = "Error: " + exception.Message; } return(r); }