Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Int32 LoginUserId = 0;

            if (HttpContext.Current.Session["UserId"] != null)
            {
                LoginUserId = Convert.ToInt32(HttpContext.Current.Session["UserId"].ToString());
            }
            User     user     = IUserService.GetSingle(LoginUserId);
            UserRole userRole = IUserRoleService.GetSingle(user.UserRoleId);

            if (Request.QueryString["hdnNumberPerPage"] != "" && Request.QueryString["hdnNumberPerPage"] != null)
            {
                hdnNumberPerPage.Value = Request.QueryString["hdnNumberPerPage"].ToString();
            }
            if (Request.QueryString["hdnCurrentPageNo"] != "" && Request.QueryString["hdnCurrentPageNo"] != null)
            {
                hdnCurrentPageNo.Value = Request.QueryString["hdnCurrentPageNo"].ToString();
            }
            if (Request.QueryString["hdnTotalRecordsCount"] != "" && Request.QueryString["hdnTotalRecordsCount"] != null)
            {
                hdnTotalRecordsCount.Value = Request.QueryString["hdnTotalRecordsCount"].ToString();
            }

            StringBuilder filter = new StringBuilder();

            filter.Append(" 1=1 ");

            if (Request.QueryString["IsNewSearch"] != "" && Request.QueryString["IsNewSearch"] != null)
            {
                IsNewSearch.Value = Request.QueryString["IsNewSearch"].ToString();
            }
            if (IsNewSearch.Value == "1")
            {
                hdnCurrentPageNo.Value = "";
            }
            if (Request.QueryString["Search"] != "" && Request.QueryString["Search"] != null)
            {
                Search.Value = Request.QueryString["Search"].ToString();
                string columnNameUsername = Converter.GetColumnNameByPropertyName <User>(nameof(Silverlake.Utility.User.Username));
                filter.Append(" and " + columnNameUsername + " like '%" + Search.Value + "%'");
                string columnNameEmail = Converter.GetColumnNameByPropertyName <User>(nameof(Silverlake.Utility.User.EmailId));
                filter.Append(" or " + columnNameEmail + " like '%" + Search.Value + "%'");
                string columnNameMobile = Converter.GetColumnNameByPropertyName <User>(nameof(Silverlake.Utility.User.MobileNumber));
                filter.Append(" or " + columnNameMobile + " like '%" + Search.Value + "%'");
            }

            string        userRoleId   = Converter.GetColumnNameByPropertyName <User>(nameof(Silverlake.Utility.User.UserRoleId));
            List <string> adminroleids = IUserRoleService.GetDataByPropertyName(nameof(UserRole.UserTypeId), "6", true, 0, 0, false).Select(x => x.Id.ToString()).ToList();

            filter.Append(" and " + userRoleId + " in (" + String.Join(",", adminroleids.ToArray()) + ")");

            if (userRole.Name == "HQ Admin")
            {
                filter.Append(" and " + userRoleId + " > " + userRole.Id + "");
            }
            else if (userRole.Name == "Regional Admin")
            {
                filter.Append(" and " + userRoleId + " > " + userRole.Id + "");
                List <Branch> Branches = new List <Branch>();
                if (user.IsAll == 0)
                {
                    List <BranchUser> userBranches = IBranchUserService.GetDataByFilter(" user_id = '" + user.Id + "' and status='1'", 0, 0, false);
                    Branches = IBranchService.GetDataByFilter(" ID not in (" + String.Join(",", userBranches.Select(x => x.BranchId).ToArray()) + ")", 0, 0, false);
                }
                else
                {
                    Branches = IBranchService.GetDataByFilter(" status='1'", 0, 0, false);
                }
                filter.Append(" and " + userRoleId + " > " + userRole.Id + " and branch_id in (" + String.Join(",", Branches.Select(x => x.Id).ToArray()) + ")");
            }
            else if (userRole.Name == "Branch Admin")
            {
                filter.Append(" and " + userRoleId + " > " + userRole.Id + "");
                filter.Append(" and " + userRoleId + " > " + userRole.Id + " and branch_id in (" + user.BranchId + ")");
            }
            int skip = 0, take = 10;

            if (hdnCurrentPageNo.Value == "")
            {
                skip = 0;
                take = 10;
                hdnNumberPerPage.Value     = "10";
                hdnCurrentPageNo.Value     = "1";
                hdnTotalRecordsCount.Value = IUserService.GetCountByFilter(filter.ToString()).ToString();
            }
            else
            {
                skip = (Convert.ToInt32(hdnCurrentPageNo.Value) - 1) * 10;
                take = 10;
            }

            List <User> users = IUserService.GetDataByFilter(filter.ToString(), skip, take, true);

            StringBuilder asb   = new StringBuilder();
            int           index = 1;

            List <Branch>     branches    = IBranchService.GetData(0, 0, false);
            List <Department> departments = IDepartmentService.GetData(0, 0, false);

            foreach (User u in users)
            {
                userRole = IUserRoleService.GetSingle(u.UserRoleId);
                Branch b = IBranchService.GetSingle(u.BranchId);

                StringBuilder departmentsHTML = new StringBuilder();
                if (userRole.Name == "Branch Admin")
                {
                    List <BranchDepartment> branchDepartments = IBranchDepartmentService.GetDataByFilter(" branch_id = '" + u.BranchId + "' and status='1'", 0, 0, false);
                    if (b.IsAll == 0)
                    {
                        departments = departments.Where(x => !(branchDepartments.Select(y => y.DepartmentId).ToList().Contains(x.Id))).ToList();
                    }
                    List <DepartmentUser> userDepartments = IDepartmentUserService.GetDataByPropertyName(nameof(DepartmentUser.UserId), u.Id.ToString(), true, 0, 0, false);
                    bool isSelectAllChecked = u.IsAll == 1 ? true : false;
                    departmentsHTML.Append(@"
                    <label class='icheck'>
                        <div class='flat-blue single-row'>
                            <div class='checkbox'>
                                <input type='checkbox' name='checkRow' class='checkRow selectAll' value='' " + (isSelectAllChecked ? "checked" : "") + @"/> <label>Select All</label><br/>
                            </div>
                        </div>
                    </label>
                ");
                    foreach (Department d in departments)
                    {
                        bool isChecked = false;
                        if (isSelectAllChecked)
                        {
                            isChecked = true;
                        }
                        else if (userDepartments.Count > 0)
                        {
                            DepartmentUser bd = userDepartments.Where(x => x.DepartmentId == d.Id && x.Status == 1).FirstOrDefault();
                            if (bd == null)
                            {
                                isChecked = true;
                            }
                        }
                        departmentsHTML.Append(@"
                        <label class='icheck'>
                            <div class='flat-green single-row'>
                                <div class='checkbox'>
                                    <input type='checkbox' name='checkRow' class='checkRow' value='" + d.Id + @"' " + (isChecked ? "checked" : "") + @"/> <label>" + d.Code + @"</label><br/>
                                </div>
                            </div>
                        </label>
                    ");
                    }
                }

                StringBuilder branchesHTML = new StringBuilder();
                if (userRole.Name == "Regional Admin")
                {
                    List <BranchUser> userBranches = IBranchUserService.GetDataByFilter(" user_id = '" + u.Id + "' and status='1'", 0, 0, false);
                    bool isSelectAllChecked        = u.IsAll == 1 ? true : false;
                    branchesHTML.Append(@"
                        <label class='icheck'>
                            <div class='flat-blue single-row'>
                                <div class='checkbox'>
                                    <input type='checkbox' name='checkRow' class='checkRow selectAll' value='' " + (isSelectAllChecked ? "checked" : "") + @"/> <label>Select All</label><br/>
                                </div>
                            </div>
                        </label>
                    ");
                    foreach (Branch br in branches)
                    {
                        bool isChecked = false;
                        if (isSelectAllChecked)
                        {
                            isChecked = true;
                        }
                        else if (userBranches.Count > 0)
                        {
                            BranchUser bd = userBranches.Where(x => x.BranchId == br.Id && x.Status == 1).FirstOrDefault();
                            if (bd == null)
                            {
                                isChecked = true;
                            }
                        }
                        branchesHTML.Append(@"
                        <label class='icheck'>
                            <div class='flat-green single-row'>
                                <div class='checkbox'>
                                    <input type='checkbox' name='checkRow' class='checkRow' value='" + br.Id + @"' " + (isChecked ? "checked" : "") + @"/> <label>" + br.Code + @"</label><br/>
                                </div>
                            </div>
                        </label>
                    ");
                    }
                }
                asb.Append(@"<tr>
                                <td class='icheck'>
                                    <div class='square single-row'>
                                        <div class='checkbox'>
                                            <input type='checkbox' name='checkRow' class='checkRow' value='" + u.Id + @"' /> <label>" + index + @"</label><br/>
                                        </div>
                                    </div>
                                    <span class='row-status'>" + (u.Status == 1 ? "<span class='label label-success'>Active</span>" : "<span class='label label-danger'>Inactive</span>") + @"</span>
                                </td>
                                <td>
                                    Username: <strong>" + u.Username + @"</strong><br />
                                    Email: <strong>" + u.EmailId + @"</strong><br />
                                    Mobile: <strong>" + u.MobileNumber + @"</strong><br />
                                    Role: <strong>" + userRole.Name + @"</strong><br />");

                if (userRole.Name == "Branch Admin")
                {
                    asb.Append(@"API Auth Token: <a href='javascript:;' class='btn btn-sm btn-primary view_batch_log'>View</a>
                                    <div class='div_batch_log hide draggableDiv'>
                                        <span class='log_close'>X</span>
                                        <table class='table mb-0'>
                                            <tr><td><strong>Api Auth Token</strong></td><td class='text-right'>User: <strong>" + u.Username + @"</strong></td></tr>
                                        </table>
                                        <div class='mini-stat clearfix text-left'>" + u.ApiAuthToken + @"</div>
                                    </div>");
                }
                asb.Append(@"</td>
                                <td style='width: 600px;'>
                                    " + (u.BranchId == 0 ? "<strong>Branches</strong><br />" + branchesHTML.ToString() : "<strong>Branch: " + b.Code + "</strong><br />") + @"
                                    " + (userRole.Name == "Branch Admin" ? "<strong>Departments</strong><br />" + departmentsHTML.ToString() : "") + @"
                                </td>
                            </tr>");
                index++;
            }
            adminsTbody.InnerHtml = asb.ToString();
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["hdnNumberPerPage"] != "" && Request.QueryString["hdnNumberPerPage"] != null)
            {
                hdnNumberPerPage.Value = Request.QueryString["hdnNumberPerPage"].ToString();
            }
            if (Request.QueryString["hdnCurrentPageNo"] != "" && Request.QueryString["hdnCurrentPageNo"] != null)
            {
                hdnCurrentPageNo.Value = Request.QueryString["hdnCurrentPageNo"].ToString();
            }
            if (Request.QueryString["hdnTotalRecordsCount"] != "" && Request.QueryString["hdnTotalRecordsCount"] != null)
            {
                hdnTotalRecordsCount.Value = Request.QueryString["hdnTotalRecordsCount"].ToString();
            }

            StringBuilder filter = new StringBuilder();

            filter.Append(" 1=1 ");

            if (Request.QueryString["IsNewSearch"] != "" && Request.QueryString["IsNewSearch"] != null)
            {
                IsNewSearch.Value = Request.QueryString["IsNewSearch"].ToString();
            }
            if (IsNewSearch.Value == "1")
            {
                hdnCurrentPageNo.Value = "";
            }
            if (Request.QueryString["Search"] != "" && Request.QueryString["Search"] != null)
            {
                Search.Value = Request.QueryString["Search"].ToString();
                string columnNameName = Converter.GetColumnNameByPropertyName <Branch>(nameof(Silverlake.Utility.Branch.Name));
                filter.Append(" and " + columnNameName + " like '%" + Search.Value + "%'");
                string columnNameCode = Converter.GetColumnNameByPropertyName <Branch>(nameof(Silverlake.Utility.Branch.Code));
                filter.Append(" or " + columnNameCode + " like '%" + Search.Value + "%'");
            }


            int skip = 0, take = 10;

            if (hdnCurrentPageNo.Value == "")
            {
                skip = 0;
                take = 10;
                hdnNumberPerPage.Value     = "10";
                hdnCurrentPageNo.Value     = "1";
                hdnTotalRecordsCount.Value = IBranchService.GetCountByFilter(filter.ToString()).ToString();
            }
            else
            {
                skip = (Convert.ToInt32(hdnCurrentPageNo.Value) - 1) * 10;
                take = 10;
            }

            List <Branch> objs = IBranchService.GetDataByFilter(filter.ToString(), skip, take, false);

            List <Department> departments = IDepartmentService.GetData(0, 0, false);

            StringBuilder asb   = new StringBuilder();
            int           index = 1;

            foreach (Branch obj in objs)
            {
                StringBuilder           departmentsHTML   = new StringBuilder();
                List <BranchDepartment> branchDepartments = IBranchDepartmentService.GetDataByPropertyName(nameof(BranchDepartment.BranchId), obj.Id.ToString(), true, 0, 0, false);
                bool isSelectAllChecked = obj.IsAll == 1 ? true : false;
                departmentsHTML.Append(@"
                    <label class='icheck'>
                        <div class='flat-blue single-row'>
                            <div class='checkbox'>
                                <input type='checkbox' name='checkRow' class='checkRow selectAll' value='' " + (isSelectAllChecked ? "checked" : "") + @"/> <label>Select All</label><br/>
                            </div>
                        </div>
                    </label>
                ");
                foreach (Department d in departments)
                {
                    bool isChecked = false;
                    if (isSelectAllChecked)
                    {
                        isChecked = true;
                    }
                    else if (branchDepartments.Count > 0)
                    {
                        BranchDepartment bd = branchDepartments.Where(x => x.DepartmentId == d.Id && x.Status == 1).FirstOrDefault();
                        if (bd == null)
                        {
                            isChecked = true;
                        }
                    }
                    departmentsHTML.Append(@"
                        <label class='icheck'>
                            <div class='flat-green single-row'>
                                <div class='checkbox'>
                                    <input type='checkbox' name='checkRow' class='checkRow' value='" + d.Id + @"' " + (isChecked ? "checked" : "") + @"/> <label>" + d.Code + @"</label><br/>
                                </div>
                            </div>
                        </label>
                    ");
                }
                Company company = ICompanyService.GetSingle(obj.CompanyId);
                asb.Append(@"<tr>
                                <td class='icheck'>
                                    <div class='square single-row'>
                                        <div class='checkbox'>
                                            <input type='checkbox' name='checkRow' class='checkRow' value='" + obj.Id + @"' /> <label>" + index + @"</label><br/>
                                        </div>
                                    </div>
                                    <span class='row-status'>" + (obj.Status == 1 ? "<span class='label label-success'>Active</span>" : "<span class='label label-danger'>Inactive</span>") + @"</span>
                                </td>
                                <td><strong>" + obj.Code + "</strong><br/>" + obj.Name + @"</td>
                                <td style='width: 300px;'>
                                    " + departmentsHTML.ToString() + @"
                                </td>
                                <td>" + obj.CreatedDate.ToString("dd/MM/yyyy") + @"</td>
                                <td>" + (obj.UpdatedDate == null ? "-" : obj.UpdatedDate.Value.ToString("dd/MM/yyyy")) + @"</td>
                            </tr>");
                index++;
            }
            branchesTBody.InnerHtml = asb.ToString();
        }
        // GET api/values
        public object Get(string apiAuthToken)
        {
            ConfigurationDTO configurationDTO = new ConfigurationDTO();
            List <User>      userMatches      = IUserService.GetDataByPropertyName(nameof(Utility.User.ApiAuthToken), apiAuthToken, true, 0, 0, false);
            User             user             = new Utility.User();

            if (userMatches.Count > 0)
            {
                user = userMatches.FirstOrDefault();
                if (user != null)
                {
                    if (user.Status == 0)
                    {
                        configurationDTO.isSuccess   = false;
                        configurationDTO.responseMsg = "User not active";
                        configurationDTO.user        = null;
                        configurationDTO.branch      = null;
                        return(configurationDTO);
                    }
                    else
                    {
                        UserRole userRole = IUserRoleService.GetSingle(user.UserRoleId);
                        if (user.BranchId == 0 && userRole.Name == "Super Admin")
                        {
                            configurationDTO.isSuccess   = true;
                            configurationDTO.responseMsg = "SA";
                            configurationDTO.user        = user;
                            configurationDTO.branch      = null;
                            return(configurationDTO);
                        }
                        else if (user.BranchId == 0 && userRole.Name == "HQ Admin")
                        {
                            configurationDTO.isSuccess   = true;
                            configurationDTO.responseMsg = "HQ Admin";
                            configurationDTO.user        = user;
                            configurationDTO.branch      = null;
                            return(configurationDTO);
                        }
                        else if (user.BranchId == 0 && userRole.Name == "Regional Admin")
                        {
                            configurationDTO.isSuccess   = true;
                            configurationDTO.responseMsg = "Regional Admin";
                            configurationDTO.user        = user;
                            configurationDTO.branch      = null;
                            return(configurationDTO);
                        }
                        else
                        {
                            Branch branch = IBranchService.GetSingle(user.BranchId);
                            if (branch.Status != 0)
                            {
                                List <Department> departments = new List <Department>();
                                if (branch.IsAll == 1)
                                {
                                    departments = IDepartmentService.GetData(0, 0, false);
                                }
                                else
                                {
                                    List <BranchDepartment> branchDepartments = IBranchDepartmentService.GetDataByFilter(" branch_id = '" + branch.Id + "' and status = '1'", 0, 0, false);
                                    departments = IDepartmentService.GetDataByFilter(" ID not in (" + String.Join(",", branchDepartments.Select(x => x.DepartmentId).ToArray()) + ") and status='1'", 0, 0, false);
                                    //departments.ForEach(x =>
                                    //{
                                    //    //x.Status = branchDepartments.Where(y => y.DepartmentId == x.Id).FirstOrDefault().Status;
                                    //    x.Status = 1;
                                    //});
                                }
                                List <DepartmentUser> userDepartments = IDepartmentUserService.GetDataByFilter(" user_id = '" + user.Id + "' and status='1'", 0, 0, false);
                                if (user.IsAll == 0)
                                {
                                    departments = departments.Where(x => !(userDepartments.Select(y => y.DepartmentId).ToList().Contains(x.Id))).ToList();
                                }
                                configurationDTO.isSuccess   = true;
                                configurationDTO.responseMsg = "Branch";
                                configurationDTO.user        = user;
                                configurationDTO.branch      = branch;
                                configurationDTO.departments = departments;
                                user.LastSyncDate            = DateTime.Now;
                                IUserService.UpdateData(user);
                                return(configurationDTO);
                            }
                            else
                            {
                                configurationDTO.isSuccess   = false;
                                configurationDTO.responseMsg = "Branch not active";
                                configurationDTO.user        = null;
                                configurationDTO.branch      = null;
                                return(configurationDTO);
                            }
                        }
                    }
                }
                else
                {
                    configurationDTO.isSuccess   = false;
                    configurationDTO.responseMsg = "User doesn't exist";
                    configurationDTO.user        = null;
                    configurationDTO.branch      = null;
                    return(configurationDTO);
                }
            }
            else
            {
                configurationDTO.isSuccess   = false;
                configurationDTO.responseMsg = "User doesn't exist";
                configurationDTO.user        = null;
                configurationDTO.branch      = null;
                return(configurationDTO);
            }
        }
Exemplo n.º 4
0
        public static object UpdateDepartments(List <IdDepartments> allObjs)
        {
            Int32 LoginUserId = 0;

            if (HttpContext.Current.Session["UserId"] != null)
            {
                LoginUserId = Convert.ToInt32(HttpContext.Current.Session["UserId"].ToString());
            }
            foreach (IdDepartments bds in allObjs)
            {
                int    branchId = bds.Id;
                Branch branch   = IBranchService.GetSingle(branchId);
                if (bds.isSelectAll)
                {
                    branch.IsAll       = 1;
                    branch.UpdatedDate = DateTime.Now;
                    branch.UpdatedBy   = LoginUserId;
                    IBranchService.UpdateData(branch);

                    List <BranchDepartment> branchDepartments = IBranchDepartmentService.GetDataByPropertyName(nameof(BranchDepartment.BranchId), branchId.ToString(), true, 0, 0, false);
                    branchDepartments.ForEach(x =>
                    {
                        x.UpdatedBy   = LoginUserId;
                        x.UpdatedDate = DateTime.Now;
                        x.Status      = 0;
                    });
                    IBranchDepartmentService.UpdateBulkData(branchDepartments);
                }
                else
                {
                    //List<Department> departments = IDepartmentService.GetData(0, 0, false);
                    List <BranchDepartment> branchDepartments = IBranchDepartmentService.GetDataByPropertyName(nameof(BranchDepartment.BranchId), branchId.ToString(), true, 0, 0, false);

                    foreach (BranchDepartment bd in branchDepartments)
                    {
                        int?deptId = bds.DepartmentIds.Where(x => x == bd.DepartmentId).FirstOrDefault();
                        if (deptId == 0)
                        {
                            BranchDepartment bdNew = bd;
                            bd.Status      = 0;
                            bd.UpdatedBy   = LoginUserId;
                            bd.UpdatedDate = DateTime.Now;
                            IBranchDepartmentService.UpdateData(bd);
                        }
                        else
                        {
                            BranchDepartment bdNew = bd;
                            bd.Status      = 1;
                            bd.UpdatedBy   = LoginUserId;
                            bd.UpdatedDate = DateTime.Now;
                            IBranchDepartmentService.UpdateData(bd);
                        }
                    }

                    foreach (int departmentId in bds.DepartmentIds)
                    {
                        BranchDepartment bd = branchDepartments.Where(x => x.DepartmentId == departmentId).FirstOrDefault();
                        if (bd == null)
                        {
                            bd = new BranchDepartment
                            {
                                BranchId     = branchId,
                                DepartmentId = departmentId,
                                CreatedBy    = LoginUserId,
                                CreatedDate  = DateTime.Now,
                                UpdatedBy    = LoginUserId,
                                UpdatedDate  = DateTime.Now,
                                Status       = 1
                            };
                            IBranchDepartmentService.PostData(bd);
                        }
                        else
                        {
                            if (bd.Status == 0)
                            {
                                bd.Status      = 1;
                                bd.UpdatedBy   = LoginUserId;
                                bd.UpdatedDate = DateTime.Now;
                                IBranchDepartmentService.UpdateData(bd);
                            }
                        }
                    }

                    branch.IsAll       = 0;
                    branch.UpdatedDate = DateTime.Now;
                    branch.UpdatedBy   = LoginUserId;
                    IBranchService.UpdateData(branch);
                }
            }
            return(true);
        }