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));
            }
        }
예제 #2
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);
        }