Пример #1
0
        public IActionResult GetById(int id)
        {
            var enterpriseClient = _enterpriseClientService.GetById(id);

            if (enterpriseClient == null)
            {
                return(Json(new
                {
                    result = "Enterprise doesn't exist"
                }));
            }

            var partner = _partnerService.GetById(enterpriseClient.PartnerId);

            return(Json(new
            {
                Id = enterpriseClient.Id,
                Name = enterpriseClient.Name,
                Location = enterpriseClient.Location,
                Partner = new { id = enterpriseClient.PartnerId, name = partner.Name }
            }));
        }
        private bool IsAuthorised(string licenceKey)
        {
            var result       = false;
            var TokenDetails = User.Claims.GetTokenDetails();


            if (string.IsNullOrEmpty(TokenDetails.Role) || string.IsNullOrEmpty(TokenDetails.Username))
            {
                return(result);
            }


            var managerTokenUser = _userService.GetByUsername(TokenDetails.Username);

            if (managerTokenUser == null && TokenDetails.Role.ToLower() == "admin")
            {
                return(true);
            }

            var subscription = _subscriptionService.GetByLicenceKey(licenceKey);

            var sub_ec = _enterpriseClientService.GetById(subscription.EnterpriseClientId);

            var sub_partner = _partnerService.GetById(sub_ec.PartnerId);

            if (TokenDetails.Role.ToLower() == "admin")
            {
                result = true;
            }
            else if (TokenDetails.Role.ToLower() == "partner")
            {
                if (sub_partner.Id == managerTokenUser.PartnerId)
                {
                    result = true;
                }
            }
            else if (TokenDetails.Role.ToLower() == "ec")
            {
                if ((sub_partner.Id == managerTokenUser.PartnerId) && (sub_ec.Id == managerTokenUser.EnterpriseId))
                {
                    result = true;
                }
            }

            return(result);
        }
        public IActionResult GetAll()
        {
            try
            {
                var TokenDetails = User.Claims.GetTokenDetails();


                if (string.IsNullOrEmpty(TokenDetails.Role) || string.IsNullOrEmpty(TokenDetails.Username))
                {
                    Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                    return(Json(string.Empty));
                }

                var managerTokenUser = _userService.GetByUsername(TokenDetails.Username);


                if (TokenDetails.Role.ToLower() == "ec")
                {
                    var enterprise        = _enterpriseClientService.GetById(managerTokenUser.EnterpriseId.Value);
                    var subscriptionsList = _subscriptionService.GetByEnterpriseId(enterprise.Id);
                    var partner           = _partnerService.GetById(enterprise.PartnerId);
                    var query             = from subscription in subscriptionsList
                                            select new
                    {
                        Id   = subscription.Id,
                        Name = subscription.Name,
                        EnterpriseClientId       = subscription.EnterpriseClientId,
                        Product                  = subscription.Product,
                        ProductName              = _productService.GetByWId(subscription.Product).Name,
                        LicencingEnvironment     = subscription.LicencingEnvironment,
                        LicencingEnvironmentName = _licenceEnvironmentService.GetBymanagerId(subscription.LicencingEnvironment).Name,
                        BrandId                  = subscription.BrandId,
                        Campaign                 = subscription.Campaign,
                        SeatCount                = subscription.SeatCount,
                        CoreAuthUsername         = subscription.CoreAuthUsername,
                        RegAuthUsername          = subscription.RegAuthUsername,
                        Status                 = subscription.Status,
                        LicenceKey             = subscription.LicenceKey,
                        ClientDownloadLocation = subscription.ClientDownloadLocation,
                        Partner                = new { id = partner.Id, name = partner.Name },
                        Enterprise             = new { id = enterprise.Id, name = enterprise.Name },
                        CreationTime           = subscription.CreationTime,
                        CancelationTime        = subscription.CancelationTime
                    };


                    return(Json(new
                    {
                        c = ResultCode.Success,
                        d = new { subscriptions = query, partners = partner, ec = enterprise }
                    }));
                }

                else if (TokenDetails.Role.ToLower() == "partner")
                {
                    var partner = _partnerService.GetById(managerTokenUser.PartnerId.Value);
                    var enterpriseClientsList = _enterpriseClientService.GetByPartnerId(partner.Id);
                    var subscriptions         = _subscriptionService.GetAll();

                    var subscriptionsList = from ec in enterpriseClientsList
                                            join sub in subscriptions
                                            on ec.Id equals sub.EnterpriseClientId
                                            select new
                    {
                        sub.Id,
                        sub.Name,
                        sub.EnterpriseClientId,
                        sub.Product,
                        sub.LicencingEnvironment,
                        sub.BrandId,
                        sub.Campaign,
                        sub.SeatCount,
                        sub.CoreAuthUsername,
                        sub.RegAuthUsername,
                        sub.Status,
                        sub.LicenceKey,
                        sub.ClientDownloadLocation,
                        enterpriseid   = ec.Id,
                        enterprisename = ec.Name,
                        sub.CreationTime,
                        sub.CancelationTime
                    };



                    var query = from subscription in subscriptionsList
                                select new
                    {
                        Id   = subscription.Id,
                        Name = subscription.Name,
                        EnterpriseClientId       = subscription.EnterpriseClientId,
                        Product                  = subscription.Product,
                        ProductName              = _productService.GetByWId(subscription.Product).Name,
                        LicencingEnvironment     = subscription.LicencingEnvironment,
                        LicencingEnvironmentName = _licenceEnvironmentService.GetBymanagerId(subscription.LicencingEnvironment).Name,
                        BrandId                  = subscription.BrandId,
                        Campaign                 = subscription.Campaign,
                        SeatCount                = subscription.SeatCount,
                        CoreAuthUsername         = subscription.CoreAuthUsername,
                        RegAuthUsername          = subscription.RegAuthUsername,
                        Status                 = subscription.Status,
                        LicenceKey             = subscription.LicenceKey,
                        ClientDownloadLocation = subscription.ClientDownloadLocation,
                        Partner                = new { id = partner.Id, name = partner.Name },
                        Enterprise             = new { id = subscription.enterpriseid, name = subscription.enterprisename },
                        CreationTime           = subscription.CreationTime,
                        CancelationTime        = subscription.CancelationTime
                    };

                    return(Json(new
                    {
                        c = ResultCode.Success,
                        d = new { subscriptions = query, partners = partner, ec = enterpriseClientsList }
                    }));
                }
                else if (TokenDetails.Role.ToLower() == "admin")
                {
                    var subscriptions     = _subscriptionService.GetAll();
                    var partners          = _partnerService.GetAll();
                    var enterpriseClients = _enterpriseClientService.GetAll();

                    var resultList = from sub in subscriptions
                                     join ec in enterpriseClients
                                     on sub.EnterpriseClientId equals ec.Id
                                     join partner in partners on ec.PartnerId equals partner.Id
                                     select new
                    {
                        sub.Id,
                        sub.Name,
                        sub.EnterpriseClientId,
                        sub.Product,
                        sub.LicencingEnvironment,
                        sub.BrandId,
                        sub.Campaign,
                        sub.SeatCount,
                        sub.CoreAuthUsername,
                        sub.RegAuthUsername,
                        sub.Status,
                        sub.LicenceKey,
                        sub.ClientDownloadLocation,
                        enterpriseid   = ec.Id,
                        enterprisename = ec.Name,
                        partnerid      = partner.Id,
                        partnername    = partner.Name,
                        sub.CreationTime,
                        sub.CancelationTime
                    };



                    var query = from sub in resultList
                                select new
                    {
                        Id   = sub.Id,
                        Name = sub.Name,
                        EnterpriseClientId       = sub.EnterpriseClientId,
                        Product                  = sub.Product,
                        ProductName              = _productService.GetByWId(sub.Product).Name,
                        LicencingEnvironment     = sub.LicencingEnvironment,
                        LicencingEnvironmentName = _licenceEnvironmentService.GetBymanagerId(sub.LicencingEnvironment).Name,
                        BrandId                  = sub.BrandId,
                        Campaign                 = sub.Campaign,
                        SeatCount                = sub.SeatCount,
                        CoreAuthUsername         = sub.CoreAuthUsername,
                        RegAuthUsername          = sub.RegAuthUsername,
                        Status                 = sub.Status,
                        LicenceKey             = sub.LicenceKey,
                        ClientDownloadLocation = sub.ClientDownloadLocation,
                        Partner                = new { id = sub.partnerid, name = sub.partnername },
                        Enterprise             = new { id = sub.enterpriseid, name = sub.enterprisename },
                        CreationTime           = sub.CreationTime,
                        CancelationTime        = sub.CancelationTime
                    };

                    return(Json(new
                    {
                        c = ResultCode.Success,
                        d = new { subscriptions = query, partners = partners, ec = enterpriseClients }
                    }));
                }
                else
                {
                    //if code reaches this point something went wrong
                    Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                    return(Json(string.Empty));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.GetLogText("dashboard_getall"));

                return(Json(new
                {
                    c = ResultCode.GenericException,
                    d = ex.Message
                }));
            }
        }
Пример #4
0
        public IActionResult Fetch(int s)
        {
            try
            {
                var subscription = _subscriptionService.GetById(s);

                if (subscription == null)
                {
                    return(Json(new
                    {
                        c = ResultCode.ReportResultCodes.SubscriptionDoesntExist,
                        d = ""
                    }));
                }

                //Check Authorization status
                if (!IsAuthorised(subscription.LicenceKey))
                {
                    Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                    return(Json(string.Empty));
                }

                Report report;


                report = _reportService.GetLatestBySubId(subscription.Id);

                if (report == null)
                {
                    return(Json(new
                    {
                        c = ResultCode.ReportResultCodes.ReportDoesntExist,
                        d = ""
                    }));
                }


                var usageReportReportRecord        = _usageReportService.GetByReportId(report.Id);
                var deviceManufacturerReportRecord = _deviceManufacturerReportService.GetByReportId(report.Id);
                var deviceOsReportRecord           = _deviceOSReportService.GetByReportId(report.Id);
                var deviceTypeReportRecord         = _deviceTypeReportService.GetByReportId(report.Id);
                var seatDetailsReportRecord        = _seatDetailsReportService.GetByReportId(report.Id).Skip(10 * 3).Take(10);


                //SubscriptionDetails Fills

                var productName    = "";
                var enterpriseName = "";
                var partnerName    = "";

                var product = _productService.GetByWId(subscription.Product);

                if (product != null)
                {
                    productName = product.Name;
                }

                var enterprise = _enterpriseClientService.GetById(subscription.EnterpriseClientId);

                if (enterprise != null)
                {
                    enterpriseName = enterprise.Name;

                    var partner = _partnerService.GetById(enterprise.PartnerId);

                    if (partner != null)
                    {
                        partnerName = partner.Name;
                    }
                }


                return(Json(new
                {
                    c = ResultCode.Success,
                    d = new
                    {
                        reportdate = report.CompletionTime,
                        reportid = report.Id,
                        subscriptiondetails = new { name = subscription.Name, enterpriseapplication = productName, seats = subscription.SeatCount, enterprisename = enterpriseName, managingpartner = partnerName, subdate = subscription.CreationTime, lk = subscription.LicenceKey, clientDownloadLocation = subscription.ClientDownloadLocation,
                                                    SubAuthUn = _subscriptionAuthService.GetBySubscriptionId(subscription.Id).Username,
                                                    SubAuthPw = _subscriptionAuthService.GetBySubscriptionId(subscription.Id).Pin },
                        usagereport = usageReportReportRecord == null ? new { report = false, available = -1, used = -1 } : new { report = true, available = usageReportReportRecord.Available, used = usageReportReportRecord.Used },
                        devicemanufacturerreport = deviceManufacturerReportRecord == null ? new { report = false, data = new List <ReportGroupItemModel>() } : new { report = true, data = GetGroupedDataTopSixObjectsTranslated(deviceManufacturerReportRecord.Data) },
                        deviceosreport = deviceOsReportRecord == null ? new { report = false, data = new List <ReportGroupItemModel>() } : new { report = true, data = GetGroupedDataTopSixObjectsTranslated(deviceOsReportRecord.Data) },
                        devicetypereport = deviceTypeReportRecord == null ? new { report = false, data = new List <ReportGroupItemModel>() } : new { report = true, data = GetGroupedDataTopSixObjectsTranslated(deviceTypeReportRecord.Data) },
                        seatdetailsreport = seatDetailsReportRecord == null ? new { report = false, data = new List <SeatDetailsReport>() } : new { report = true, data = GetSeatDetailsReportRecordTranslated(seatDetailsReportRecord.ToList()) }
                    }
                }));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.GetLogText("reportapi_fetch"));

                return(Json(new
                {
                    c = ResultCode.GenericException,
                    d = ex.Message
                }));
            }
        }
Пример #5
0
        public async Task <IActionResult> GetById(int id)
        {
            try
            {
                var managerUser = _userService.GetById(id);

                if (managerUser == null)
                {
                    return(Json(new
                    {
                        c = ResultCode.UserResultCodes.UserDoesntExistGet,
                        d = ""
                    }));
                }

                var user = await _userManager.FindByEmailAsync(managerUser.Username);

                if (user == null)
                {
                    return(Json(new
                    {
                        c = ResultCode.UserResultCodes.UserDoesntExistGet,
                        d = ""
                    }));
                }

                var roles = await _userManager.GetRolesAsync(user);


                var role = roles.FirstOrDefault();


                if (managerUser.PartnerId == null)
                {
                    return(Json(new
                    {
                        Id = managerUser.Id,
                        Username = managerUser.Username,
                        FirstName = managerUser.Firstname,
                        LastName = managerUser.Lastname,
                        Role = role
                    }));
                }
                else
                {
                    var partner = _partnerService.GetById(managerUser.PartnerId.Value);

                    if (managerUser.EnterpriseId == null)
                    {
                        return(Json(new
                        {
                            c = ResultCode.Success,
                            d = new
                            {
                                Id = managerUser.Id,
                                Username = managerUser.Username,
                                FirstName = managerUser.Firstname,
                                LastName = managerUser.Lastname,
                                Role = role,
                                Partner = new { id = partner.Id, name = partner.Name },
                            }
                        }));
                    }
                    else
                    {
                        var enterprise = _enterpriseClientService.GetById(managerUser.EnterpriseId.Value);



                        return(Json(new
                        {
                            c = ResultCode.Success,
                            d = new
                            {
                                Id = managerUser.Id,
                                Username = managerUser.Username,
                                FirstName = managerUser.Firstname,
                                LastName = managerUser.Lastname,
                                Role = role,
                                Partner = new { id = partner.Id, name = partner.Name },
                                Enterprise = new { id = enterprise.Id, name = enterprise.Name }
                            }
                        }));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.GetLogText("userapi_getbyid"));

                return(Json(new
                {
                    c = ResultCode.GenericException,
                    d = ex.Message
                }));
            }
        }