Exemple #1
0
        public string UpdateLicense(int concurrentUserCount, string[] selectedSubscription)
        {
            List <string> teamIdList = new List <string>();

            teamIdList.Add(TempData["Teamid"].ToString());
            List <int>             listOfProId = ExtractLicenseData(selectedSubscription);
            TeamLicenseDataMapping mapping     = new TeamLicenseDataMapping()
            {
                ConcurrentUserCount = concurrentUserCount, ProductIdList = listOfProId, TeamList = teamIdList
            };
            HttpClient client   = WebApiServiceLogic.CreateClient(ServiceType.OnPremiseWebApi);
            var        response = client.PostAsJsonAsync("api/License/CreateTeamLicence", mapping).Result;

            if (!response.IsSuccessStatusCode)
            {
                var jsonData = response.Content.ReadAsStringAsync().Result;
                var obj      = JsonConvert.DeserializeObject <ResponseFailure>(jsonData);
                return(response.ReasonPhrase + " - " + obj.Message);
            }
            else
            {
                if (teamIdList.Contains(LicenseSessionState.Instance.SelectedTeam.Id.ToString()))//doubt
                {
                    var subscriptionDetails = OnPremiseSubscriptionLogic.GetUserLicenseForUser();
                    LicenseSessionState.Instance.UserSubscriptionList = subscriptionDetails;
                }
            }
            return(String.Empty);
        }
Exemple #2
0
        /// <summary>
        /// function to create the License  for multiple User . This function will be used for bulk license mapping to
        /// multiple User.
        /// </summary>
        /// <param name="licList">license List</param>
        /// <param name="userIdList">user Id List</param>
        /// <returns></returns>
        public bool CreateMultipleTeamLicense(TeamLicenseDataMapping model)
        {
            LicenseLogic licLogic = new LicenseLogic();

            foreach (var teamId in model.TeamList)
            {
                for (int concurrentUserIndex = 0; concurrentUserIndex < model.ConcurrentUserCount; concurrentUserIndex++)
                {
                    int id = int.Parse(teamId);
                    for (int index = 0; index < model.ProductIdList.Count; index++)
                    {
                        var         proId = model.ProductIdList[index];
                        var         data  = Work.LicenseDataRepository.GetData(l => l.ProductId == proId).ToList().Select(l => l.Id).ToList();
                        var         licId = licLogic.GetUnassignedLicenseForTeam(model.ProductIdList[index]);
                        TeamLicense tl    = new TeamLicense()
                        {
                            LicenseId = licId.Id,
                            TeamId    = id,
                            ProductId = proId
                        };
                        CreateTeamLicense(tl);
                    }
                }
            }
            return(true);
        }
        public HttpResponseMessage AddTeamLicense(TeamLicenseDataMapping model)
        {
            var status = teamLicenselogic.CreateMultipleTeamLicense(model);

            if (status)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Success"));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, userLicenselogic.ErrorMessage));
            }
        }
Exemple #4
0
        public TeamConcurrentUserResponse UpdateConcurrentUsers(Team team)
        {
            TeamConcurrentUserResponse concurentUserResponse = new TeamConcurrentUserResponse();

            concurentUserResponse.TeamId = team.Id;

            var dbTeamObj   = teamLogic.GetTeamById(team.Id);
            var teamLicList = teamLicenseLogic.GetTeamLicense(team.Id);

            if (dbTeamObj.ConcurrentUserCount == 0) // specifying concurrent user  for first time
            {
                teamLogic.UpdateConcurrentUser(team);
            }
            //If dbConcurrent user is greater than the changed valuee
            else if (dbTeamObj.ConcurrentUserCount > team.ConcurrentUserCount)
            {
                var proList = teamLicList.Select(t => t.ProductId).Distinct();
                foreach (var pro in proList)
                {
                    var licList = teamLicList.Where(t => t.ProductId == pro).ToList();
                    for (int k = team.ConcurrentUserCount; k < licList.Count; k++)
                    {
                        var deleteLic = licList[k];
                        if (deleteLic.IsMapped)
                        {
                            userLicLogic.RevokeTeamLicenseFromUser(deleteLic.Id);
                        }
                        licLogic.UpdateLicenseStatus(deleteLic.LicenseId, false);
                        teamLicenseLogic.RemoveLicenseByLicenseId(deleteLic.LicenseId);
                    }
                }
                teamLogic.UpdateConcurrentUser(team);
            }
            //If dbConcurrent user is lesser than the changed value
            else if (dbTeamObj.ConcurrentUserCount < team.ConcurrentUserCount)
            {
                var  requiredLicense    = team.ConcurrentUserCount - dbTeamObj.ConcurrentUserCount;
                var  proIds             = teamLicList.Select(l => l.ProductId).Distinct();
                bool isLicenseAvailable = true;
                foreach (var pro in proIds)
                {
                    var licAvailableCount = licLogic.GetAvailableLicenseCountByProduct(pro);
                    isLicenseAvailable &= licAvailableCount >= requiredLicense;
                }
                if (!isLicenseAvailable)
                {
                    concurentUserResponse.ErrorMessage     = "Not much license Exist";
                    concurentUserResponse.UserUpdateStatus = false;
                    concurentUserResponse.OldUserCount     = dbTeamObj.ConcurrentUserCount;
                    return(concurentUserResponse);
                }
                else
                {
                    TeamLicenseDataMapping licMappingObj = new TeamLicenseDataMapping();
                    licMappingObj.ConcurrentUserCount = requiredLicense;
                    licMappingObj.ProductIdList       = proIds.ToList();
                    licMappingObj.TeamList            = new List <string>
                    {
                        team.Id.ToString()
                    };
                    teamLicenseLogic.CreateMultipleTeamLicense(licMappingObj);
                }

                teamLogic.UpdateConcurrentUser(team);
            }

            concurentUserResponse.UserUpdateStatus = true;
            return(concurentUserResponse);
        }