// GET: Team
        public ActionResult TeamContainer()
        {
            string      userId   = string.Empty;
            List <Team> teamList = null;

            if (!LicenseSessionState.Instance.IsSuperAdmin)
            {
                userId = LicenseSessionState.Instance.User.UserId;
            }
            if (LicenseSessionState.Instance.TeamList == null || LicenseSessionState.Instance.TeamList.Count == 0)
            {
                teamList = OnPremiseSubscriptionLogic.GetTeamList(userId);
                LicenseSessionState.Instance.TeamList = teamList;
            }
            if (LicenseSessionState.Instance.TeamList == null || LicenseSessionState.Instance.TeamList.Count == 0)
            {
                ViewBag.SelectedTeamId = "";
                return(View());
            }
            if (LicenseSessionState.Instance.SelectedTeam == null)
            {
                var teamObj = LicenseSessionState.Instance.TeamList.FirstOrDefault(t => t.IsDefaultTeam == true);
                if (teamObj == null)
                {
                    teamObj = LicenseSessionState.Instance.TeamList.First();
                }
                ViewBag.SelectedTeamId = teamObj.Id;
            }
            else
            {
                ViewBag.SelectedTeamId = LicenseSessionState.Instance.SelectedTeam.Id;
            }
            return(View());
        }
Example #2
0
        public ActionResult Index()
        {
            List <SelectListItem> items = new List <SelectListItem>();

            items.Add(new SelectListItem()
            {
                Text = "1", Value = "1"
            });
            items.Add(new SelectListItem()
            {
                Text = "2", Value = "2"
            });
            items.Add(new SelectListItem()
            {
                Text = "3", Value = "3"
            });
            items.Add(new SelectListItem()
            {
                Text = "4", Value = "4"
            });
            items.Add(new SelectListItem()
            {
                Text = "5", Value = "5"
            });
            items.Add(new SelectListItem()
            {
                Text = "6", Value = "6"
            });
            items.Add(new SelectListItem()
            {
                Text = "7", Value = "7"
            });
            items.Add(new SelectListItem()
            {
                Text = "8", Value = "8"
            });
            items.Add(new SelectListItem()
            {
                Text = "9", Value = "9"
            });
            items.Add(new SelectListItem()
            {
                Text = "10", Value = "10"
            });
            ViewData["UserCountList"] = items;
            string userId = string.Empty;

            if (!LicenseSessionState.Instance.IsSuperAdmin)
            {
                userId = LicenseSessionState.Instance.User.UserId;
            }
            var teamList = OnPremiseSubscriptionLogic.GetTeamList(userId);

            LicenseSessionState.Instance.TeamList = teamList;
            return(View(LicenseSessionState.Instance.TeamList));
        }
        public List <Team> LoadTeamsByUserId(string userId, string actiontype)
        {
            List <Team> teamList           = null;
            var         mappedTeams        = OnPremiseSubscriptionLogic.GetTeamList(userId);
            var         existingTeamIdList = mappedTeams.Select(t => t.Id).ToList();

            if (actiontype == "AssignTeam")
            {
                teamList = LicenseSessionState.Instance.TeamList.Where(t => !existingTeamIdList.Contains(t.Id) && t.AdminId == LicenseSessionState.Instance.SelectedTeam.AdminId).ToList();
            }
            else
            {
                teamList = mappedTeams.Where(t => t.IsDefaultTeam == false).ToList();
            }
            return(teamList);
        }
        public async Task <ActionResult> LogIn(LoginViewModel model)
        {
            User user = null;

            if (ModelState.IsValid)
            {
                // Authentication is supparated for the On Premises user and Centralized User. Global Admin will  be authenticate with Centralised DB
                // and on premises user and admin will be authenticated with on premise DB
                var status = await _accountLogic.AuthenticateUser(model, ServiceType.OnPremiseWebApi);

                if (status)
                {
                    user = await _accountLogic.GetUserData(ServiceType.OnPremiseWebApi);

                    if (user.Roles.Contains("SuperAdmin"))
                    {
                        status = await _accountLogic.AuthenticateUser(model, ServiceType.CentralizeWebApi);
                    }
                }
                else
                {
                    status = await _accountLogic.AuthenticateUser(model, ServiceType.CentralizeWebApi);

                    if (status)
                    {
                        user = await _accountLogic.GetUserData(ServiceType.CentralizeWebApi);
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid Credentials");
                        return(View());
                    }
                }
                if (user == null)
                {
                    ModelState.AddModelError("", _accountLogic.ErrorMessage);
                    return(View());
                }
                LicenseSessionState.Instance.User          = user;
                LicenseSessionState.Instance.IsGlobalAdmin = LicenseSessionState.Instance.User.Roles.Contains("BackendAdmin");
                LicenseSessionState.Instance.IsSuperAdmin  = LicenseSessionState.Instance.User.Roles.Contains("SuperAdmin");

                if (LicenseSessionState.Instance.IsSuperAdmin)
                {
                    LicenseSessionState.Instance.IsAdmin = true;
                }
                else
                {
                    LicenseSessionState.Instance.IsAdmin = LicenseSessionState.Instance.User.Roles.Contains("Admin");
                }

                if (!LicenseSessionState.Instance.IsGlobalAdmin && !LicenseSessionState.Instance.IsAdmin)
                {
                    LicenseSessionState.Instance.IsTeamMember = true;
                }
                LicenseSessionState.UserId       = user.UserId;
                LicenseSessionState.ServerUserId = user.ServerUserId;
                SignInAsync(user, true);
                if (LicenseSessionState.Instance.IsSuperAdmin)
                {
                    AuthorizeBackendService service = new AuthorizeBackendService();
                    service.SyncDataToOnpremise();
                }
                LicenseSessionState.Instance.IsAuthenticated = true;
                if (LicenseSessionState.Instance.IsGlobalAdmin)
                {
                    if (String.IsNullOrEmpty(user.FirstName))
                    {
                        return(RedirectToAction("Profile", "User"));
                    }
                    if (LicenseSessionState.Instance.IsGlobalAdmin)
                    {
                        return(RedirectToAction("Index", "User"));
                    }
                    return(RedirectToAction("Home", "Dashboard"));
                }
                if (LicenseSessionState.Instance.TeamList == null || LicenseSessionState.Instance.TeamList.Count == 0)
                {
                    string userId = string.Empty;
                    if (!LicenseSessionState.Instance.IsSuperAdmin)
                    {
                        userId = LicenseSessionState.Instance.User.UserId;
                    }

                    var teamList = OnPremiseSubscriptionLogic.GetTeamList(userId);
                    LicenseSessionState.Instance.TeamList = teamList;

                    if (teamList.Count == 0)
                    {
                        ViewData["IsTeamListPopupVisible"] = false;
                        return(View());
                    }
                    else if (teamList.Count == 1)
                    {
                        LicenseSessionState.Instance.SelectedTeam = teamList.FirstOrDefault();
                        var userLoginObj = IsConcurrentUserLoggedIn();
                        if (userLoginObj.IsUserLoggedIn)
                        {
                            if (String.IsNullOrEmpty(user.FirstName))
                            {
                                return(RedirectToAction("Profile", "User"));
                            }
                            if (LicenseSessionState.Instance.IsGlobalAdmin)
                            {
                                return(RedirectToAction("Index", "User"));
                            }
                            return(RedirectToAction("Home", "Dashboard"));
                        }
                        else
                        {
                            ClearSession();
                            ModelState.AddModelError("", "Maximum user has logged in Please try after some time");
                            return(View());
                        }
                    }
                }
                ViewData["IsTeamListPopupVisible"] = LicenseSessionState.Instance.TeamList.Count > 0 && LicenseSessionState.Instance.SelectedTeam == null;
                return(View());
            }
            else
            {
                ModelState.AddModelError("", "Invalid Credentials");
            }
            return(View());
        }