Exemple #1
0
        public void CompanieUserRoleSave(List <int> roleItems, int companyId)
        {
            FoxSecDBContext dBContext     = new FoxSecDBContext();
            int             currentUserId = 0;

            if (CurrentUser.Get().IsSuperAdmin)
            {
                currentUserId = companyId;
            }
            else if (CurrentUser.Get().IsCompanyManager)
            {
                currentUserId = CurrentUser.Get().CompanyId.Value;
            }

            var companieRolesRecords = dBContext.CompanieRoles.Where(y => y.CompanyId == currentUserId).Any() ? dBContext.CompanieRoles.Where(x => !x.IsDeleted && x.CompanyId == currentUserId).ToList() : null;

            if (companieRolesRecords != null)
            {
                foreach (var roles in companieRolesRecords)
                {
                    roles.IsDeleted = true;
                }
                dBContext.SaveChanges();
            }
            foreach (int roleId in roleItems)
            {
                var companieRoleModel = new CompanyRoleModel {
                    CompanyId = currentUserId, RoleId = roleId, IsDeleted = false
                };
                dBContext.CompanieRoles.Add(companieRoleModel);
                dBContext.SaveChanges();
            }
        }
        public ActionResult Search(string name, string comment, string cardSer, string cardDk, string cardCode, string company, string title, int filter, int departmentId, int?nav_page, int?rows, int?sort_field, int?sort_direction,
                                   int countryId, int locationId, int buildingId, int companyId, int floorId)
        {
            if (nav_page < 0)
            {
                nav_page = 0;
            }
            FoxSecDBContext    db        = new FoxSecDBContext();
            List <FSCameras>   FSCameras = UsersByCamera();
            IEnumerable <item> camaras   = new List <item>();

            //Mapper.Map(FSCameras, camaras);
            IEnumerable <value> filt_camras = new List <value>();
            var gridshort = CreateViewModel <LiveVideoListViewModel>();

            //var uvm = CreateViewModel<LiveVideoListViewModel>();
            //IEnumerable<item> Camralist = new List<item>();
            if (comment != "")
            {
                gridshort.Comment = true;
                //return PartialView("List", uvm);
            }
            else
            {
                var Live_camera = db.FSCameras;
            }

            var uvm = CreateViewModel <LiveVideoListViewModel>();

            FSCameras = ApplyUserStatusFilter(FSCameras, filter).ToList();

            //IEnumerable<value> list = new List<value>();
            Mapper.Map(FSCameras, filt_camras);

            if (sort_field.HasValue && sort_direction.HasValue)
            {
                if (sort_direction.Value == 0)
                {
                    filt_camras = filt_camras.OrderBy(x => x.Name).ToList();
                }
                else
                {
                    filt_camras = filt_camras.OrderByDescending(x => x.Name).ToList();
                }
            }
            //IEnumerable<value> list = new List<value>();
            //Mapper.Map(FSCameras, list);
            uvm.Paginator = SetupPaginator(ref filt_camras, nav_page, rows);
            uvm.Paginator.DivToRefresh = "AreaTabPeopleSearchResults";
            uvm.Paginator.Prefix       = "Usersss";
            uvm.Users1         = filt_camras;
            uvm.FilterCriteria = 1;
            return(PartialView("List", uvm));
        }
Exemple #3
0
        public ActionResult Edit(int id)
        {
            var cevm    = CreateViewModel <CompanyEditViewModel>();
            var company = _companyRepository.FindById(id);

            Mapper.Map(company, cevm.Company);
            var building_ids = GetUserBuildings(_buildingRepository, _userRepository);
            var buildings    = _buildingRepository.FindAll().Where(x => !x.IsDeleted && building_ids.Contains(x.Id));

            Mapper.Map(buildings, cevm.BuildingItems);

            //var cbos =
            //      company.CompanyBuildingObjects.OrderBy(x => x.BuildingObject.BuildingId).Where(x => !x.IsDeleted && (x.BuildingObject.TypeId == 1)).GroupBy(
            //          cbo => cbo.BuildingObject.BuildingId);

            var cbos =
                company.CompanyBuildingObjects.OrderBy(x => x.BuildingObject.BuildingId).Where(x => !x.IsDeleted && (x.BuildingObject.TypeId == 1 || x.BuildingObject.TypeId == 2 || x.BuildingObject.TypeId == 3 || x.BuildingObject.TypeId == 8 || x.BuildingObject.TypeId == 9 || x.BuildingObject.TypeId == 10 || x.BuildingObject.TypeId == 11)).GroupBy(
                    cbo => cbo.BuildingObject.BuildingId);

            foreach (var cbo in cbos)
            {
                var company_building_item = GetFloorItems(cbo.FirstOrDefault().BuildingObject.BuildingId, id);
                company_building_item.BuildingItems = cevm.BuildingItems;
                cevm.Company.CompanyBuildingItems.Add(company_building_item);
            }
            var complist = _companyRepository.FindAll().Where(x => x.IsDeleted == false && x.Active == true && x.ParentId == null && x.Id != id).OrderBy(y => y.Name).ToList();

            cevm.CompanyItems = complist;
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select ParentCompanieId from CompanieSubCompanies where IsDeleted=0 and CompanyId='" + id + "'", con);
            DataTable      dt = new DataTable();

            da.Fill(dt);
            con.Close();
            List <int> arr = new List <int>();

            foreach (DataRow dr in dt.Rows)
            {
                arr.Add(Convert.ToInt32(dr["ParentCompanieId"]));
            }
            cevm.SelCompanyItems = arr.ToList();
            var roleList = _roleRepository.FindAll(x => !x.IsDeleted && x.Active && x.RoleTypeId >= CurrentUser.Get().RoleTypeId).ToList();

            List <SelectListItem> roleListItems = new List <SelectListItem>();
            List <UserRoleItem>   userRole      = new List <UserRoleItem>();

            FoxSecDBContext dBContext            = new FoxSecDBContext();
            var             companyRoleListItems = dBContext.CompanieRoles.Where(x => !x.IsDeleted && x.CompanyId == id).Select(y => y.RoleId).ToList();

            roleList.ForEach(x => { var addRoleItems = new SelectListItem {
                                        Selected = companyRoleListItems.Contains(x.Id) ? true:false, Text = x.Name, Value = x.Id.ToString()
                                    }; roleListItems.Add(addRoleItems); });
            cevm.FoxSecUser.RoleItems = roleListItems;
            User user = _userRepository.FindById(CurrentUser.Get().Id);

            //roleList.ForEach(x => { var role = new UserRoleItem { IsSelected = user.UserRoles.Any(y => y.RoleId == y.Id && !y.IsDeleted), RoleName = x.Name, RoleDescription = "", RoleId = x.Id, ValidFrom = user.UserRoles.Any(userRoles => userRoles.RoleId == x.Id && !userRoles.IsDeleted) ? user.UserRoles.Where(userRoles => userRoles.RoleId == x.Id && !userRoles.IsDeleted).FirstOrDefault().ValidFrom.ToString("dd.MM.yyyy") : string.Empty, ValidTo = user.UserRoles.Any(userRoles => userRoles.RoleId == x.Id && !userRoles.IsDeleted) ? user.UserRoles.Where(userRoles => userRoles.RoleId == x.Id && !userRoles.IsDeleted).FirstOrDefault().ValidTo.ToString("dd.MM.yyyy") : string.Empty }; userRole.Add(role); });
            //cevm.FoxSecUser.UserRoleItems.Roles = userRole;


            return(PartialView(cevm));
        }
        //     public ActionResult UserLogOn(string UserName, string Password, string returnUrl)
        //     {

        //      var err_msg = string.Empty;
        //if (ModelState.IsValid)
        //         {
        //             User user;
        //             FoxSecDBContext db = new FoxSecDBContext();

        //	if (_membershipService.ValidateUser(UserName, Password, out user))
        //	{
        //                 //Send log
        //                 //illi 25.12.1012 Logger4SendingEMail.LogSender.Info(string.Format("User \"{0}\" has entered!", UserName));
        //                 //illi 25.12.1012 Logger4SendingEMail.InitLogger();



        //                 // CheckUserAuthentication(UserName);

        //                 var user_roles = user.UserRoles;
        //		var check_date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
        //		var role = user_roles.Where(ur => !ur.IsDeleted && ur.ValidTo >= check_date && ur.ValidFrom <= check_date).FirstOrDefault();

        //                 int role_id = role.RoleId;
        //                 Session["Role_ID"] = role_id;
        //                 Session["User_Id"] = role.UserId;
        //                 //int comp_id = role.CompanyId;

        //                 var rolename = db.UserRoles.SqlQuery("select Id,Name from Roles where Id=" + role_id).ToList();
        //                 //rolee = db.Database.ExecuteSqlCommand("select Name from Roles where Id="+role_id);
        //                 if (rolename != null)
        //                 {
        //                     Session["Role_Name"] = rolename[0].Name;
        //                 }
        //                 if (role != null)
        //		{
        //                     //var rvm = CreateViewModel<RoleEditViewModel>();
        //                     //Mapper.Map(_roleRepository.FindById(role_id), rvm.Role);
        //                     var menues = role.Role.Menues.ToList().Contains(1);
        //                     if(menues)
        //                     {
        //                         _formsService.SignIn(UserName, false);

        //                         var host = Request.UserHostAddress;
        //                         var xml_message = new XElement(XMLLogLiterals.LOG_MESSAGE);
        //                         var logon_params = new List<string>();
        //                         logon_params.Add(UserName);
        //                         var xml_user_logon = XMLLogMessageHelper.TemplateToXml("LogMessageUserLogon", logon_params);
        //                         xml_message.Add(xml_user_logon);
        //                         var flag = "";

        //                         _logService.CreateLog(user.Id, "web", flag, host, user.CompanyId, xml_message.ToString());
        //                     }
        //                     else
        //                     {
        //                         err_msg = ViewResources.SharedStrings.AccountNoActiveTab;
        //                         ModelState.AddModelError("", err_msg);
        //                     }
        //                 }
        //		else
        //		{
        //			err_msg = ViewResources.SharedStrings.AccountNoActiveRole;
        //			ModelState.AddModelError("", err_msg);
        //		}
        //	}
        //	else
        //	{
        //		err_msg = ViewResources.SharedStrings.AccountIncorrectPasword;
        //		ModelState.AddModelError("", err_msg);
        //	}
        //         }

        //return Json(new
        //{
        //	IsSucceed = ModelState.IsValid,
        //	Msg = ModelState.IsValid ? string.Empty : err_msg
        //});
        //     }

        public ActionResult UserLogOn(string UserName, string Password, string returnUrl)
        {
            var err_msg = string.Empty;

            if (ModelState.IsValid)
            {
                User            user;
                FoxSecDBContext db = new FoxSecDBContext();
                if (_membershipService.ValidateUser(UserName, Password, out user))
                {
                    var user_roles = user.UserRoles;
                    var check_date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                    var role       = user_roles.Where(ur => !ur.IsDeleted && ur.ValidTo >= check_date && ur.ValidFrom <= check_date).FirstOrDefault();

                    if (role == null)
                    {
                        err_msg = ViewResources.SharedStrings.LogonRoleError;
                        ModelState.AddModelError("", err_msg);
                    }
                    else
                    {
                        int role_id = role.RoleId;
                        Session["Role_ID"] = role_id;
                        Session["User_Id"] = role.UserId;
                        //int comp_id = role.CompanyId;
                        var rolename = db.UserRoles.SqlQuery("select Id,Name from Roles where Id=" + role_id).ToList();
                        con.Open();
                        SqlCommand cmd       = new SqlCommand("select FirstName+' '+LastName from Users where id='" + role.UserId + "'", con);
                        string     firstname = Convert.ToString(cmd.ExecuteScalar());
                        con.Close();
                        //rolee = db.Database.ExecuteSqlCommand("select Name from Roles where Id="+role_id);
                        if (rolename != null)
                        {
                            Session["Role_Name"] = rolename[0].Name;
                        }
                        if (role != null)
                        {
                            //var rvm = CreateViewModel<RoleEditViewModel>();
                            //Mapper.Map(_roleRepository.FindById(role_id), rvm.Role);
                            var menues = role.Role.Menues.ToList().Contains(1);
                            if (menues)
                            {
                                _formsService.SignIn(UserName, false);

                                var host         = Request.UserHostAddress;
                                var xml_message  = new XElement(XMLLogLiterals.LOG_MESSAGE);
                                var logon_params = new List <string>();
                                logon_params.Add(firstname);
                                var xml_user_logon = XMLLogMessageHelper.TemplateToXml("LogMessageUserLogon", logon_params);
                                xml_message.Add(xml_user_logon);
                                var flag = "";

                                _logService.CreateLog(user.Id, "web", flag, host, user.CompanyId, xml_message.ToString());
                            }
                            else
                            {
                                err_msg = ViewResources.SharedStrings.AccountNoActiveTab;
                                ModelState.AddModelError("", err_msg);
                            }
                        }
                        else
                        {
                            err_msg = ViewResources.SharedStrings.AccountNoActiveRole;
                            ModelState.AddModelError("", err_msg);
                        }
                    }
                }
                else
                {
                    err_msg = ViewResources.SharedStrings.AccountIncorrectPasword;
                    ModelState.AddModelError("", err_msg);
                }
            }
            return(Json(new
            {
                IsSucceed = ModelState.IsValid,
                Msg = ModelState.IsValid ? string.Empty : err_msg
            }));
        }