Exemple #1
0
        public void AddResetPasswordDetails(Guid EmailID, string EmailAddress, string Active)
        {
            using (ECommerceEntities db = new ECommerceEntities())
            {
                try
                {
                    //ResetPassword RP = new ResetPassword();
                    t_ResetPassword TRP = new t_ResetPassword();
                    TRP.EmailID = EmailID;
                    TRP.EmailAddress = EmailAddress;
                    TRP.ActiveStatus = "Y";
                    db.t_ResetPassword.Add(TRP);
                    db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    var errorMessages = ex.EntityValidationErrors
                    .SelectMany(x => x.ValidationErrors)
                    .Select(x => x.ErrorMessage);
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
            }
        }
 protected override bool AuthorizeCore(HttpContextBase httpContext)
 {
     bool authorize = false;
     using (ECommerceEntities db = new ECommerceEntities())
     {
         UserManagerFK UM = new UserManagerFK();
         foreach(var roles in userAssignedRoles)
         {
             authorize = UM.IsUserInRole(httpContext.User.Identity.Name, roles);
             if (authorize)
                 return true;
         }
     }
     return authorize;
 }
Exemple #3
0
        //Sign up - save the sign up date to the database
        public void AddUserAccount(UserModel user, AddressModel address)
        {
            using (ECommerceEntities db = new ECommerceEntities())
            {
                try
                {
                    PasswordManager PM = new PasswordManager();
                    t_Users US = new t_Users();
                    US.UserName = user.Username;
                    US.Password = PM.Encrypt(user.Password);
                    US.FirstName = user.FirstName;
                    US.LastName = user.LastName;
                    US.Email = user.Email;
                    US.Gender = user.Gender;
                    db.t_Users.Add(US);
                    //db.SaveChanges();
                    var result = db.Database.ExecuteSqlCommand("exec upSaveUser @UserName, @Password, @Email, @FirstName, @Surname, @Gender", new SqlParameter("UserName", US.UserName),
                        new SqlParameter("Password", US.Password), new SqlParameter("Email", US.Email), new SqlParameter("FirstName", US.FirstName), new SqlParameter("Surname", US.LastName),
                        new SqlParameter("Gender", US.Gender));

                    //AddressModel AD = new AddressModel();
                    t_UsersAddress TAD = new t_UsersAddress();
                    TAD.AddressNumber = address.AddressNumber;
                    TAD.AddressPostalCode = address.AddressPostalCode;
                    TAD.AddressRoadName = address.AddressRoadName;
                    TAD.AddressSuburb = address.AddressSuburb;

                    TAD.UID = US.UID;
                    TAD.AddressCity = address.AddressCity;
                    db.t_UsersAddress.Add(TAD);
                    //db.SaveChanges();

                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
Exemple #4
0
 //Get all the roles from the database
 public List<RoleAvailable> GetAllRoles()
 {
     using (ECommerceEntities db = new ECommerceEntities())
     {
         var roles = db.t_Roles.Select(o => new RoleAvailable
         {
             RoleID = o.RoleID,
             RoleName = o.RoleName,
             RoleType = o.RoleType
         }).ToList();
         return roles;
     }
 }
Exemple #5
0
 //public int GetUserID(string Email)
 //{
 //    using (ECommerceEntities db = new ECommerceEntities())
 //    {
 //        var user = db.t_Users.Where(o => o.Email.Equals(Email));
 //        if (user.Any())
 //        {
 //            return user.First().UID;
 //        }
 //        else
 //        {
 //            return 0;
 //        }
 //    }
 //}
 //Check if the user in the role or not
 public bool IsUserInRole(string LoginName, string RoleName)
 {
     using (ECommerceEntities db = new ECommerceEntities())
     {
         t_Users SU = db.t_Users.Where(o => o.UserName.ToUpper().Equals(LoginName))?.FirstOrDefault();
         if (SU != null)
         {
             var roles =
                 from q in db.t_UserRoles
                 join r in db.t_Roles on q.RoleID
                 equals r.RoleID
                 //join s in db.t_Users on q.UID equals s.UID
                 //where s.UID == q.UID
                 where r.RoleID.Equals(q.RoleID) && q.UID.Equals(SU.UID)
                 select r.RoleName;
             if (roles != null)
             {
                 return roles.Any();
             }
         }
         return false;
     }
 }
Exemple #6
0
 //Check if the username is already in exisistance
 public bool IsLoginNameExist(string loginName)
 {
     using (ECommerceEntities db = new ECommerceEntities())
     {
         return db.t_Users.Where(o => o.UserName.Equals(loginName)).Any();
     }
 }
Exemple #7
0
 //Check if the email address is already in exisistance
 public bool IsEmailExist(string EmailAddress)
 {
     using (ECommerceEntities db = new ECommerceEntities())
     {
         return db.t_Users.Where(p => p.Email.Equals(EmailAddress)).Any();
     }
 }
Exemple #8
0
 //get the users password
 public string GetUserPassword(string LoginUserName)
 {
     using (ECommerceEntities db = new ECommerceEntities())
     {
         var user = db.t_Users.Where(o => o.UserName.ToUpper().Equals(LoginUserName));
         if (user.Any())
         {
             return user.FirstOrDefault().Password;
         }
         else
         {
             return string.Empty;
         }
     }
 }
Exemple #9
0
 //Get the user ID
 public int GetUserID(string LoginName)
 {
     using (ECommerceEntities db = new ECommerceEntities())
     {
         var user = db.t_Users.Where(o => o.UserName.Equals(LoginName));
         if (user.Any())
         {
             return user.FirstOrDefault().UID;
         }
     }
     return 0;
 }
Exemple #10
0
 public string GetUserGender(string LoginName)
 {
     using (ECommerceEntities db = new ECommerceEntities())
     {
         var user = db.t_Users.Where(o => o.UserName.Equals(LoginName));
         if (user.Any())
         {
             return user.FirstOrDefault().Gender;
         }
     }
     return "";
 }
Exemple #11
0
 public string GetUserEmail(string Email)
 {
     using (ECommerceEntities db = new ECommerceEntities())
     {
         var user = db.t_Users.Where(o => o.Email.Equals(Email));
        if(user.Any())
         {
             return user.First().Email;
         }
        else
         {
             return string.Empty;
         }
     }
 }
Exemple #12
0
        public UserDataView GetUserDataView(string LoginName)
        {
            UserDataView UDV = new UserDataView();
            List<UserProfile> Profile = GetAllUsers();
            List<RoleAvailable> roles = GetAllRoles();

            int? userAssignedRole = 0, UserID = 0;
            string UserGender = string.Empty;
            UserGender = GetUserGender(LoginName);
            UserID = GetUserID(LoginName);

            using (ECommerceEntities db = new ECommerceEntities())
            {
                userAssignedRole = db.t_UserRoles.Where(o => o.UID == UserID)?.FirstOrDefault().RoleID;
                UserGender = db.t_Users.Where(o => o.Gender == UserGender)?.FirstOrDefault().Gender;
            }

            List<Gender> Genders = new List<Gender>();
            Genders.Add(new Gender { Text = "Male", Value = "M" });
            Genders.Add(new Gender { Text = "Female", Value = "F" });

            UDV.UserProfiles = Profile;
            UDV.UserRole = new UserRole { SelectedRoleID = userAssignedRole, UserRoleList = roles };
            UDV.UserGender = new UserGender { SelectedGender = UserGender, Gender = Genders };
            return UDV;
        }
Exemple #13
0
        //Get the list of all the users and their roles
        public List<UserProfile> GetAllUsers()
        {
            List<UserProfile> Profiles = new List<UserProfile>();
            List<UserRoleTable> Roles = new List<UserRoleTable>();
            using (ECommerceEntities db = new ECommerceEntities())
            {
                UserProfile UP;
                UserRoleTable URT = new UserRoleTable();
                var user = db.t_Users.ToList();
                foreach (t_Users t in db.t_Users)
                {
                    UP = new UserProfile();
                    UP.UID = t.UID;
                    UP.Username = t.UserName;
                    UP.Password = t.Password;

                    var SUP = db.t_Users.Find(t.UID);
                    db.Database.SqlQuery<UserRole>("GetUserRole", t.UID);

                    if (SUP != null)
                    {
                        UP.FirstName = SUP.FirstName;
                        UP.LastName = SUP.LastName;
                        UP.Gender = SUP.Gender;
                        UP.Email = SUP.Email;
                    }

                    var item = db.t_UserRoles.Where(o => o.UID == t.UID).ToList();
                    if (item != null)
                    {
                        var roleIDs = item.Select(x => x.RoleID).ToList();

                        List<string> tempRoles = new List<string>();
                        roleIDs.ForEach(x => tempRoles.Add(db.t_Roles.Find(x).RoleName));

                        foreach (var item2 in tempRoles)
                        {
                            UP.Roles += item2 + " | ";
                        }

                    }

                    Profiles.Add(UP);
                }
            }
            return Profiles;
        }