Exemplo n.º 1
0
 public List <InSubUserDetails> GetSubUser()
 {
     try
     {
         List <InSubUserDetails> inSubUserDetails = new List <InSubUserDetails>();
         List <InSubUser>        inSubUsers       = new DB_A3E3FF_scampus2020Context().InSubUser.ToList();
         List <InUsers>          inUsers          = new DB_A3E3FF_scampusMaster2020Context().InUsers.ToList();
         List <InConfiguration>  inConfigurations = new DB_A3E3FF_scampusMaster2020Context().InConfiguration.ToList();
         //using (DB_A3E3FF_scampus2020Context db = DB_A3E3FF_scampus2020Context())
         //{
         inSubUserDetails = (from b in inSubUsers
                             from e in inUsers
                             .Where(x => x.Id == b.EmpId).DefaultIfEmpty()
                             from c in inConfigurations
                             .Where(x => x.ConfId == b.ConfigId).DefaultIfEmpty()
                             select new InSubUserDetails
         {
             Id = b.Id,
             ConfigId = b.ConfigId,
             ConfigName = c.Name,
             EmpName = e.Username,
             EmpId = b.EmpId,
             SubUserName = b.SubUserName,
             CreatedBy = b.CreatedBy,
             CreatedDate = b.CreatedDate,
             IsActive = b.IsActive
         }).Where(x => x.IsActive == true).OrderByDescending(x => x.CreatedDate).ToList();
         return(inSubUserDetails);
         //}
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 2
0
 public List <InBranchDetails> GetBranch()
 {
     try
     {
         List <InBranchDetails> inBranchDetails = new List <InBranchDetails>();
         List <InBranch>        inBranches      = new DB_A3E3FF_scampus2020Context().InBranch.ToList();
         List <user>            inUsers         = new DB_A3E3FF_scampusMaster2020Context().InUsers.Where(x => x.IsActive == true).Select(x => new user {
             EmpId   = x.Id,
             EmpName = x.Username
         }).ToList();
         List <user> inusers1 = new DB_A3E3FF_scampus2020Context().AdminUsers.Where(x => x.Status == true).Select(x => new user {
             EmpId   = x.Userid,
             EmpName = x.Username
         }).ToList();
         inUsers.AddRange(inusers1);
         List <ConfigurationMaster> inConfigurations = new DB_A3E3FF_scampusMaster2020Context().ConfigurationMaster.ToList();
         //using (DB_A3E3FF_scampus2020Context db = DB_A3E3FF_scampus2020Context())
         //{
         inBranchDetails = (from b in inBranches
                            from e in inUsers
                            .Where(x => x.EmpId == b.EmpId).DefaultIfEmpty()
                            from c in inConfigurations
                            .Where(x => x.ConfigId == b.ConfigId).DefaultIfEmpty()
                            select new InBranchDetails
         {
             BranchId = b.BranchId,
             BranchName = b.BranchName,
             Location = b.Location,
             Address = b.Address,
             ContactNumber1 = b.ContactNumber1,
             ContactNumber2 = b.ContactNumber2,
             Email = b.Email,
             ContactPerson = b.ContactPerson,
             BranchCode = b.BranchCode,
             Gstin = b.Gstin,
             State = b.State,
             District = b.District,
             Smsapiurl = b.Smsapiurl,
             Apikey = b.Apikey,
             SenderId = b.SenderId,
             BranchLogo = b.BranchLogo,
             PrintHeaderFile = b.PrintHeaderFile,
             PrintFooterFile = b.PrintFooterFile,
             ConfigId = b.ConfigId,
             EmpName = e.EmpName,
             EmpId = b.EmpId,
             ConfigName = c.ConfigName,
             CreatedBy = b.CreatedBy,
             CreatedDate = b.CreatedDate,
             IsActive = b.IsActive
         }).Where(x => x.IsActive == true).OrderByDescending(x => x.CreatedDate).ToList();
         return(inBranchDetails);
         //}
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 3
0
        public UserCred Authenticate(UserCred userCred)
        {
            try
            {
                UserCred users = new UserCred();
                if (userCred.IsSuperAdmin == true)
                {
                    using (DB_A3E3FF_scampusMaster2020Context db = new DB_A3E3FF_scampusMaster2020Context())
                    {
                        var user = db.InUsers.Where(x => x.Username == userCred.Username && x.Password == userCred.Password && x.IsActive == true).FirstOrDefault();
                        //if user not found
                        if (user == null)
                        {
                            return(null);
                        }
                        else
                        {
                            //if user found
                            var confdata = db.ConfigurationMaster.Where(x => x.ConfigId.ToString() == user.Configuration.ToString() && x.BaseUrl == userCred.BaseUrl && x.IsActive == true).FirstOrDefault();
                            if (confdata != null)
                            {
                                var tokenHandler = new JwtSecurityTokenHandler();
                                var key          = Encoding.ASCII.GetBytes(_appSettings.Key);

                                var tokenDescriptor = new SecurityTokenDescriptor
                                {
                                    Subject = new ClaimsIdentity(new Claim[] {
                                        new Claim(ClaimTypes.Name, user.Username),
                                        new Claim(ClaimTypes.Role, user.Role),
                                        new Claim(ClaimTypes.Version, "3.1")
                                    }),
                                    Expires            = DateTime.UtcNow.AddMinutes(15),
                                    SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
                                };
                                var token = tokenHandler.CreateToken(tokenDescriptor);
                                users.Token    = tokenHandler.WriteToken(token);
                                users.Role     = user.Role;
                                users.userId   = user.Id;
                                users.ConfigId = user.Configuration;
                                users.BaseUrl  = user.BaseUrl;
                            }
                            else
                            {
                                return(null);
                            }
                        }
                    }
                }
                else
                {
                    List <ConfigurationMaster> configurationMaster = new DB_A3E3FF_scampusMaster2020Context().ConfigurationMaster.Where(x => x.IsActive == true).ToList();
                    using (DB_A3E3FF_scampus2020Context db1 = new DB_A3E3FF_scampus2020Context())
                    {
                        var user = db1.AdminUsers.Where(x => x.Username == userCred.Username && x.Password == userCred.Password && x.Status == true).FirstOrDefault();
                        //if user not found
                        if (user == null)
                        {
                            return(null);
                        }
                        else
                        {
                            var confiData = configurationMaster.Where(x => x.ConfigId == user.ConfigSettings && x.BaseUrl == userCred.BaseUrl && x.IsActive == true).FirstOrDefault();
                            //if user found
                            if (confiData != null)
                            {
                                var tokenHandler = new JwtSecurityTokenHandler();
                                var key          = Encoding.ASCII.GetBytes(_appSettings.Key);

                                var tokenDescriptor = new SecurityTokenDescriptor
                                {
                                    Subject = new ClaimsIdentity(new Claim[] {
                                        new Claim(ClaimTypes.Name, user.Username),
                                        new Claim(ClaimTypes.Role, user.Role),
                                        new Claim(ClaimTypes.Version, "3.1")
                                    }),
                                    Expires            = DateTime.UtcNow.AddMinutes(15),
                                    SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
                                };
                                var token = tokenHandler.CreateToken(tokenDescriptor);
                                users.Token  = tokenHandler.WriteToken(token);
                                users.Role   = user.Role;
                                users.userId = user.Userid;

                                users.BaseUrl  = user.Baseurl;
                                users.ConfigId = user.ConfigSettings;
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        return(users);
                    }
                }
                return(users);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 4
0
        public Result Login(string username, string password, bool?Role, string baseusrl)
        {
            try
            {
                if (Role == true)
                {
                    using (DB_A3E3FF_scampusMaster2020Context db = new DB_A3E3FF_scampusMaster2020Context())
                    {
                        var data = db.InUsers.Where(x => x.Username == username && x.Password == password && x.BaseUrl == baseusrl && x.IsActive == true).FirstOrDefault();

                        if (data != null)
                        {
                            var confdata = db.ConfigurationMaster.Where(x => x.ConfigId.ToString() == data.Configuration.ToString() && x.IsActive == true).FirstOrDefault();
                            if (confdata != null)
                            {
                                return(new Result {
                                    StatusCode = 1, Message = "Login success ..!"
                                });
                            }
                            else
                            {
                                return(new Result {
                                    StatusCode = -1, Message = "Login Failed"
                                });
                            }
                        }
                        else
                        {
                            return(new Result {
                                StatusCode = -1, Message = "Login Failed"
                            });
                        }
                    }
                }
                else
                {
                    List <ConfigurationMaster> configurationMaster = new DB_A3E3FF_scampusMaster2020Context().ConfigurationMaster.Where(x => x.IsActive == true).ToList();
                    using (DB_A3E3FF_scampus2020Context db1 = new DB_A3E3FF_scampus2020Context())
                    {
                        var data = db1.AdminUsers.Where(x => x.Username == username && x.Password == password && x.Baseurl == baseusrl && x.Status == true).FirstOrDefault();
                        if (data != null)
                        {
                            var confdata = configurationMaster.Where(x => x.ConfigId.ToString() == data.ConfigSettings.ToString() && x.IsActive == true).FirstOrDefault();
                            if (confdata != null)
                            {
                                return(new Result {
                                    StatusCode = 1, Message = "Login success ..!"
                                });
                            }
                            else
                            {
                                return(new Result {
                                    StatusCode = -1, Message = "Login Failed"
                                });
                            }
                        }
                        else
                        {
                            return(new Result {
                                StatusCode = -1, Message = "Login Failed"
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(new Result {
                    StatusCode = -1, Message = ex.Message
                });

                throw ex;
            }
        }
Exemplo n.º 5
0
        public List <AdminUserDetails> GetAdminUsers(string role)
        {
            try
            {
                List <AdminUserDetails>    adminUsers           = new List <AdminUserDetails>();
                List <ConfigurationMaster> configurationMasters = new DB_A3E3FF_scampusMaster2020Context().ConfigurationMaster.Where(x => x.IsActive == true).ToList();
                List <AdminUsers>          adminUsers1          = new DB_A3E3FF_scampus2020Context().AdminUsers.Where(x => x.Status == true).ToList();
                List <InUsers>             inUsers = new DB_A3E3FF_scampusMaster2020Context().InUsers.Where(x => x.IsActive == true).ToList();
                List <AdminUserDetails>    user    = new List <AdminUserDetails>(); //DB_A3E3FF_scampus2020Context().AdminUsers.Where(x => x.Role == "Admin" && x.Status == true).ToList();

                using (DB_A3E3FF_scampus2020Context db = new DB_A3E3FF_scampus2020Context())
                {
                    user = (from a in adminUsers1
                            from c in configurationMasters
                            .Where(x => x.ConfigId == a.ConfigSettings).DefaultIfEmpty()
                            select new AdminUserDetails
                    {
                        Userid = a.Userid,
                        Username = a.Username,
                        Password = a.Password,
                        EmailId = a.EmailId,
                        ConfigSettings = a.ConfigSettings,
                        ConfigName = c.ConfigName,
                        Role = a.Role,
                        Status = a.Status,
                        AccountStatus = a.AccountStatus,
                        CreatedBy = a.CreatedBy,
                        CreatedDate = a.CreatedDate
                    }).Where(x => x.Status == true && x.Role == "Admin").ToList();
                }
                if (role == "Super Admin")
                {
                    adminUsers = (from a in inUsers
                                  from c in configurationMasters
                                  .Where(x => x.ConfigId == a.Configuration).DefaultIfEmpty()
                                  select new AdminUserDetails
                    {
                        Userid = a.Id,
                        Username = a.Username,
                        Password = a.Password,
                        EmailId = a.EmailId,
                        ConfigSettings = a.Configuration,
                        ConfigName = c.ConfigName,
                        Status = a.IsActive,
                        Role = a.Role,
                        Baseurl = a.BaseUrl,
                        AccountStatus = a.AccountStatus,
                        CreatedBy = a.CreatedBy,
                        CreatedDate = a.CreatedDate
                    }).OrderByDescending(x => x.CreatedDate).Where(x => x.Status == true).ToList();

                    adminUsers.AddRange(user);
                }
                else if (role == "Admin")
                {
                    adminUsers = (from a in adminUsers1
                                  from c in configurationMasters
                                  .Where(x => x.ConfigId == a.ConfigSettings).DefaultIfEmpty()
                                  select new AdminUserDetails
                    {
                        Userid = a.Userid,
                        Username = a.Username,
                        Password = a.Password,
                        EmailId = a.EmailId,
                        ConfigSettings = a.ConfigSettings,
                        ConfigName = c.ConfigName,
                        Status = a.Status,
                        Role = a.Role,
                        Baseurl = a.Baseurl,
                        AccountStatus = a.AccountStatus,
                        CreatedBy = a.CreatedBy,
                        CreatedDate = a.CreatedDate
                    }).OrderByDescending(x => x.CreatedDate).Where(x => x.Status == true).ToList();
                }
                //adminUsers = (from a in adminUsers1
                //              from c in configurationMasters
                //                        .Where(x => x.ConfigId == a.ConfigSettings).DefaultIfEmpty()
                //                  select new AdminUserDetails
                //                  {
                //                      Userid = a.Userid,
                //                      Username = a.Username,
                //                      Password = a.Password,
                //                      EmailId = a.EmailId,
                //                      ConfigSettings = a.ConfigSettings,
                //                      ConfigName = c.ConfigName,
                //                      Status = a.Status,
                //                      AccountStatus = a.AccountStatus,
                //                      CreatedBy = a.CreatedBy,
                //                      CreatedDate = a.CreatedDate
                //                  }).OrderByDescending(x => x.CreatedDate).Where(x => x.Status == true).ToList();
                // }
                return(adminUsers);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }