示例#1
0
        public async Task <GetBadgesResponse> Get()
        {
            var response = new GetBadgesResponse
            {
                Badges = await Task.FromResult(Badges.BadgeList),
            };

            if (MemoryCacher.GetValue(Cache.BadgeRanking) is IEnumerable <BadgeRanking> cacheBadgeRankings)
            {
                response.BadgeRankings = cacheBadgeRankings;
            }
            else
            {
                var badgeRankings = await _databaseRepository.GetBadgeRanking();

                if (badgeRankings != null)
                {
                    MemoryCacher.Add(Cache.BadgeRanking, badgeRankings, DateTimeOffset.UtcNow.AddDays(1));
                }

                response.BadgeRankings = badgeRankings;
            }

            return(response);
        }
示例#2
0
        public GameResponse JoinGame([FromUri] JoinGameRequest request)
        {
            Game game = (Game)MemoryCacher.GetValue(request.GameId);

            MemoryCacher.Replace(game.Id.ToString(), game, DateTimeOffset.UtcNow.AddHours(1));
            return(new GameResponse(game));
        }
示例#3
0
        public GameResponse ResolveStack([FromUri] ResolveStackRequest request)
        {
            Game game = (Game)MemoryCacher.GetValue(request.GameId);

            game.ResolveStack();
            return(new GameResponse(game));
        }
示例#4
0
        public GameResponse ActivateEffect([FromBody] ActivateEffectRequest request)
        {
            Game game = (Game)MemoryCacher.GetValue(request.GameId);

            game.ActivateEffect();
            return(new GameResponse(game));
        }
示例#5
0
        public GameResponse CastSpell([FromBody] CastSpellRequest request)
        {
            Game game = (Game)MemoryCacher.GetValue(request.GameId);

            game.CastSpell(request.PlayerId, request.CardId, request.Targets);
            return(new GameResponse(game));
        }
示例#6
0
 public List <GroupProductStatistics> GetGroupArchiveProdStatistics()//[FromBody] ProductStatistics _ps
 {
     try
     {
         List <GroupProductStatistics> ListPS;
         // ---
         ListPS = (List <GroupProductStatistics>)MemoryCacher.GetValue("GroupArchiveProductStatistics");
         if (ListPS == null)
         {
             ListPS = ldbFetch.GetArchiveLdbGroupProductStatistics(365);
             if (ListPS == null)
             {
                 return(null); // ListPS = StatisticsActs.GetArchiveProdStatistics("");
             }
             MemoryCacher.Add("GroupArchiveProductStatistics", ListPS, DateTimeOffset.Now.AddMinutes(1));
         }
         // ---
         return(ListPS);
     }
     catch (Exception ex)
     {
         DBHelper.LogFile(ex);
         return(null);
     }
 }
示例#7
0
        public GameResponse StartGame([FromUri] SelectDeckRequest request)
        {
            Game game = (Game)MemoryCacher.GetValue(request.GameId);

            game.Status = Status.Active;
            return(new GameResponse(game));
        }
示例#8
0
        public IHttpActionResult Get(Guid formTemplateId, Guid id)
        {
            if (formTemplateId == Guid.Empty)
                return BadRequest("form template id is empty");

            if (id == Guid.Empty)
                return BadRequest("metric id is empty");

            var cacheKey = $"{CACHE_KEY}_{formTemplateId}_{id}";
            var cacheEntry = MemoryCacher.GetValue(cacheKey);

            if (cacheEntry == null)
            {
                var metric = GetMetric(formTemplateId, id);
                if (metric == null)
                    return NotFound();

                var result = Mapper.Map(metric, metric.GetType(), typeof(MetricDTO));
                MemoryCacher.Add(cacheKey, result, DateTimeOffset.UtcNow.AddMinutes(1));

                return Ok(result);
            }
            else
            {
                return new CachedResult<object>(cacheEntry, TimeSpan.FromMinutes(1), this);
            }
        }
示例#9
0
        public IActionResult DashBoard()
        {
            if (User.IsSignedIn())
            {
                var startDate = new DateTime();
                var endDate   = new DateTime();

                if (MemoryCacher.Contain(CacheKey.START_DATE.GetDescription()))
                {
                    startDate = Convert.ToDateTime(MemoryCacher.GetValue(CacheKey.START_DATE.GetDescription()));
                }
                else
                {
                    startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month - 1, DateTime.Now.Day);
                }

                if (MemoryCacher.Contain(CacheKey.END_DATE.GetDescription()))
                {
                    endDate = Convert.ToDateTime(MemoryCacher.GetValue(CacheKey.END_DATE.GetDescription()));
                }
                else
                {
                    endDate = DateTime.Now;
                }

                var highCharts = getCharts(startDate, endDate);
                return(View(new ChartsViewModel {
                    Charts = highCharts, StartDate = startDate, EndDate = endDate
                }));
            }
            else
            {
                return(View("~/views/account/login"));
            }
        }
示例#10
0
 public List <ProductStatistics> GetO90DProdStatistics()//[FromBody] ProductStatistics _ps
 {
     try
     {
         List <ProductStatistics> ListPS;
         // ---
         ListPS = (List <ProductStatistics>)MemoryCacher.GetValue("O90DProductStatistics");
         if (ListPS == null)
         {
             ListPS = ldbFetch.GetLiveLdbProductStatistics("O90D");
             if (ListPS == null)
             {
                 return(null); // ListPS = StatisticsActs.GetYearProdStatistics("D");
             }
             MemoryCacher.Add("O90DProductStatistics", ListPS, DateTimeOffset.Now.AddMinutes(1));
         }
         // ---
         return(ListPS);
     }
     catch (Exception e)
     {
         DBHelper.LogFile(e);
         return(null);
     }
 }
示例#11
0
        public Dictionary <string, string> GetRegister(string registername, MetadataViewModel model)
        {
            string role = GetSecurityClaim("role");

            MemoryCacher memCacher = new MemoryCacher();

            var cache = memCacher.GetValue("registeritem-" + registername);

            List <RegisterItem> RegisterItems = new List <RegisterItem>();

            if (cache != null)
            {
                RegisterItems = cache as List <RegisterItem>;
            }

            if (RegisterItems.Count < 1)
            {
                System.Net.WebClient c = new System.Net.WebClient();
                c.Encoding = System.Text.Encoding.UTF8;
                var data     = c.DownloadString(System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "api/register/" + registername);
                var response = Newtonsoft.Json.Linq.JObject.Parse(data);

                var items = response["containeditems"];

                foreach (var item in items)
                {
                    var    id           = item["id"].ToString();
                    var    owner        = item["owner"].ToString();
                    string organization = item["owner"].ToString();

                    var registerItem = new RegisterItem {
                        Id = id, Label = item["label"].ToString(), Organization = organization
                    };

                    if (!RegisterItems.Contains(registerItem))
                    {
                        RegisterItems.Add(registerItem);
                    }
                }

                var logLines = RegisterItems.Select(l => l.Id + ": " + l.Label);
                Log.Info(string.Format("Setting cache for registername: {0}, items: " + Environment.NewLine + " {1}", registername, string.Join(Environment.NewLine, logLines)));
                memCacher.Set("registeritem-" + registername, RegisterItems, new DateTimeOffset(DateTime.Now.AddYears(1)));
            }

            Dictionary <string, string> RegisterItemsForUser = new Dictionary <string, string>();

            foreach (var item in RegisterItems)
            {
                if (!string.IsNullOrWhiteSpace(role) && role.Equals("nd.metadata_admin") || model.HasAccess(item.Organization))
                {
                    RegisterItemsForUser.Add(item.Id, item.Label);
                }
            }

            RegisterItemsForUser = RegisterItemsForUser.OrderBy(o => o.Value).ToDictionary(o => o.Key, o => o.Value);

            return(RegisterItemsForUser);
        }
        public async Task <IHttpActionResult> Get(Guid id)
        {
            // not necessary to validate empty IDs,
            // because the FormTemplateService method
            // returns an empty FormTemplateDTO.
            //if (id == Guid.Empty)
            //    return BadRequest("id is empty");

            if (CurrentUser is OrgUser)
            {
                var orgAdminRole = "Organisation administrator";
                var isOrgAdmin   = await ServiceContext.UserManager.IsInRoleAsync(CurrentOrgUser.Id, orgAdminRole);

                var cacheKey = isOrgAdmin ?
                               $"{CACHE_KEY}_{ORG_ADMIN_KEY}_{id}_{CurrentOrgUser.Id}" :
                               $"{CACHE_KEY}_{id}_{CurrentOrgUser.Id}";

                var cacheEntry = MemoryCacher.GetValue(cacheKey);
                if (cacheEntry == null)
                {
                    var template = FormTemplatesService.Get(id);
                    if (template == null)
                    {
                        return(NotFound());
                    }

                    MemoryCacher.Add(cacheKey, template, DateTimeOffset.UtcNow.AddMinutes(1));

                    return(Ok(template));
                }
                else
                {
                    var result = (FormTemplateDTO)cacheEntry;
                    return(new CachedResult <FormTemplateDTO>(result, TimeSpan.FromMinutes(1), this));
                }
            }

            // else if current user is SuperUser
            var _cacheKey   = $"{CACHE_KEY}_{ADMIN_KEY}_{id}";
            var _cacheEntry = MemoryCacher.GetValue(_cacheKey);

            if (_cacheEntry == null)
            {
                var template = FormTemplatesService.Get(id);
                if (template == null)
                {
                    return(NotFound());
                }

                MemoryCacher.Add(_cacheKey, template, DateTimeOffset.UtcNow.AddMinutes(1));

                return(Ok(template));
            }
            else
            {
                var response = (FormTemplateDTO)_cacheEntry;
                return(new CachedResult <FormTemplateDTO>(response, TimeSpan.FromMinutes(1), this));
            }
        }
示例#13
0
        public async Task <IHttpActionResult> Get(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(Ok(Mapper.Map <ProjectDTO>(new Project())));
            }

            if (CurrentUser is OrgUser)
            {
                var orgAdminRole = "Organisation administrator";
                var isOrgAdmin   = await ServiceContext.UserManager.IsInRoleAsync(CurrentOrgUser.Id, orgAdminRole);

                var cacheKey = isOrgAdmin ?
                               $"{CACHE_KEY}_{ORG_ADMIN_KEY}_{id}_{CurrentOrgUser.Id}" :
                               $"{CACHE_KEY}_{id}_{CurrentOrgUser.Id}";

                var cacheEntry = MemoryCacher.GetValue(cacheKey);
                if (cacheEntry == null)
                {
                    var project = ProjectService.Get(CurrentUser, id);
                    if (project == null)
                    {
                        return(NotFound());
                    }

                    MemoryCacher.Add(cacheKey, project, DateTimeOffset.UtcNow.AddMinutes(1));

                    return(Ok(project));
                }
                else
                {
                    var result = (ProjectDTO)cacheEntry;
                    return(new CachedResult <ProjectDTO>(result, TimeSpan.FromMinutes(1), this));
                }
            }

            // else if current user is SuperUser
            var _cacheKey   = $"{CACHE_KEY}_{ADMIN_KEY}_{id}";
            var _cacheEntry = MemoryCacher.GetValue(_cacheKey);

            if (_cacheEntry == null)
            {
                var project = ProjectService.Get(CurrentUser, id);
                if (project == null)
                {
                    return(NotFound());
                }

                MemoryCacher.Add(_cacheKey, project, DateTimeOffset.UtcNow.AddMinutes(1));

                return(Ok(project));
            }
            else
            {
                var response = (ProjectDTO)_cacheEntry;
                return(new CachedResult <ProjectDTO>(response, TimeSpan.FromMinutes(1), this));
            }
        }
示例#14
0
 public bool IsCacheTokenSidExists(string guidSID)
 {
     guidSID = guidSID.Replace("-", "");
     if (cacher.GetValue(guidSID) != null)
     {
         return(true);
     }
     return(false);
 }
        // GET api/orgInvitations/{organisationId?}
        public IHttpActionResult Get(Guid?organisationId = null)
        {
            if (CurrentUser is OrgUser)
            {
                var cacheKey   = $"{CACHE_KEY}_{CurrentOrgUser.Organisation.Id}";
                var cacheEntry = MemoryCacher.GetValue(cacheKey);

                if (cacheEntry == null)
                {
                    var invitations = UnitOfWork.OrgInvitationsRepository
                                      .AllAsNoTracking
                                      .Where(x => x.OrganisationId == CurrentOrgUser.Organisation.Id)
                                      .ToList();

                    var result = invitations
                                 .Select(i => Mapper.Map <OrgInvitationDTO>(i))
                                 .ToList();

                    MemoryCacher.Add(cacheKey, result, DateTimeOffset.UtcNow.AddMinutes(1));

                    return(Ok(result));
                }
                else
                {
                    var result = (List <OrgInvitationDTO>)cacheEntry;
                    return(new CachedResult <List <OrgInvitationDTO> >(result, TimeSpan.FromMinutes(1), this));
                }
            }

            // else if current user is SuperUser or PlatformUser
            var _cacheKey   = organisationId.HasValue ? $"{CACHE_KEY}_{organisationId.Value}" : CACHE_KEY;
            var _cacheEntry = MemoryCacher.GetValue(_cacheKey);

            if (_cacheEntry == null)
            {
                var _invitations = UnitOfWork.OrgInvitationsRepository.AllAsNoTracking;

                if (organisationId.HasValue)
                {
                    _invitations = _invitations.Where(x => x.OrganisationId == organisationId.Value);
                }

                var retVal = _invitations
                             .ToList()
                             .Select(i => Mapper.Map <OrgInvitationDTO>(i))
                             .ToList();

                MemoryCacher.Add(_cacheKey, retVal, DateTimeOffset.UtcNow.AddMinutes(1));

                return(Ok(retVal));
            }
            else
            {
                var retVal = (List <OrgInvitationDTO>)_cacheEntry;
                return(new CachedResult <List <OrgInvitationDTO> >(retVal, TimeSpan.FromMinutes(1), this));
            }
        }
示例#16
0
        public GameResponse SelectDeck([FromUri] SelectDeckRequest request)
        {
            Game game = (Game)MemoryCacher.GetValue(request.GameId);

            game.Selectdeck(request.PlayerId, request.DeckId);

            MemoryCacher.Replace(game.Id.ToString(), game, DateTimeOffset.UtcNow.AddHours(1));

            return(new GameResponse(game));
        }
示例#17
0
        public static WaitingRoom GetWaitingRoom()
        {
            WaitingRoom retVal = (WaitingRoom)MemoryCacher.GetValue(WaitingRoomKey);

            if (retVal == null)
            {
                retVal = new WaitingRoom();
            }
            return(retVal);
        }
        protected CachedRestController(string cacheKey, List <T> defaultValues)
        {
            CacheKey = cacheKey;
            var inCache = MemoryCacher.GetValue(CacheKey) as List <T>;

            if (inCache == null)
            {
                MemoryCacher.Add(CacheKey, defaultValues);
            }
            Values = inCache ?? defaultValues;
        }
        public IHttpActionResult Get(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest("id is empty"));
            }

            if (CurrentUser is OrgUser)
            {
                var cacheKey   = $"{CACHE_KEY}_{id}";
                var cacheEntry = MemoryCacher.GetValue(cacheKey);

                if (cacheEntry == null)
                {
                    var category = UnitOfWork.FormTemplateCategoriesRepository
                                   .AllAsNoTracking
                                   .Where(c => c.Id == id && c.OrganisationId == CurrentOrgUser.OrganisationId)
                                   .Select(c => Mapper.Map <FormTemplateCategoryDTO>(c))
                                   .SingleOrDefault();

                    MemoryCacher.Add(cacheKey, category, DateTimeOffset.UtcNow.AddMinutes(1));

                    return(Ok(category));
                }
                else
                {
                    var result = (FormTemplateCategoryDTO)cacheEntry;
                    return(new CachedResult <FormTemplateCategoryDTO>(result, TimeSpan.FromMinutes(1), this));
                }
            }

            // else if current user is SuperUser
            var _cacheKey   = $"{CACHE_KEY}_{id}";
            var _cacheEntry = MemoryCacher.GetValue(_cacheKey);

            if (_cacheEntry == null)
            {
                var _category = UnitOfWork.FormTemplateCategoriesRepository
                                .AllAsNoTracking
                                .Where(c => c.Id == id)
                                .Select(c => Mapper.Map <FormTemplateCategoryDTO>(c))
                                .SingleOrDefault();

                MemoryCacher.Add(_cacheKey, _category, DateTimeOffset.UtcNow.AddMinutes(1));

                return(Ok(_category));
            }
            else
            {
                var retVal = (FormTemplateCategoryDTO)_cacheEntry;
                return(new CachedResult <FormTemplateCategoryDTO>(retVal, TimeSpan.FromMinutes(1), this));
            }
        }
示例#20
0
 public HttpResponseMessage SendToList([FromBody] NotificationModel value)
 {
     try
     {
         //NotificationActivity _request = JsonConvert.DeserializeObject<NotificationActivity>(value);
         if (value.RecipientIDs == null || string.IsNullOrEmpty(value.Content))
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest));
         }
         IEnumerable <string> _sessionGuid;
         User _usr = new User();
         if (Request.Headers.TryGetValues("SessionGuid", out _sessionGuid))
         {
             string _sessID = _sessionGuid.First();
             if (MemoryCacher.GetValue(_sessID) == null)
             {
                 return(Request.CreateResponse(HttpStatusCode.Forbidden));
             }
             string _userID = MemoryCacher.GetValue(_sessID).ToString();
             _usr = bus_user.Get_ById(_userID);
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest));
         }
         List <string> _webappid = value.AppIDs.Where(x => bus_AppInfo.Get_ById(x).Type == AppTypeConst.WEBAPP).ToList();
         if (_webappid != null && _webappid.Count > 0)
         {
             NotificationActivity _notif = bus_NotificationActivity.Create(new NotificationActivity
             {
                 Content      = value.Content,
                 UserID       = _usr.Id,
                 RecipientIDs = value.RecipientIDs,
                 AppIDs       = _webappid,
                 SendTime     = DateTime.Now
             });
             foreach (string _id in _webappid)
             {
                 notificationHub.SendSegment(_notif.Id, value.RecipientIDs, _id, value.Content);
             }
             return(Request.CreateResponse(HttpStatusCode.OK, new { NotifID = _notif.Id }));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest));
         }
     }
     catch (Exception ex)
     {
         LogGenerationHelper.WriteToFile(ex.Message);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError));
     }
 }
示例#21
0
        public Dictionary <string, string> GetListOfOrganizations(string culture = Culture.NorwegianCode)
        {
            MemoryCacher memCacher = new MemoryCacher();

            var cache = memCacher.GetValue("organizations_" + culture);

            Dictionary <string, string> Organizations = new Dictionary <string, string>();

            if (cache != null)
            {
                Organizations = cache as Dictionary <string, string>;
            }

            if (Organizations.Count < 1)
            {
                System.Net.WebClient c = new System.Net.WebClient();
                c.Encoding = System.Text.Encoding.UTF8;
                var data     = c.DownloadString(System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "api/register/organisasjoner");
                var response = Newtonsoft.Json.Linq.JObject.Parse(data);

                var orgs = response["containeditems"];

                c.Headers.Remove("Accept-Language");
                c.Headers.Add("Accept-Language", Culture.EnglishCode);

                var dataEnglish     = c.DownloadString(System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "api/register/organisasjoner");
                var responseEnglish = Newtonsoft.Json.Linq.JObject.Parse(dataEnglish);

                var orgsEnglish = responseEnglish["containeditems"];

                for (int o = 0; o < orgs.Count(); o++)
                {
                    if (!Organizations.ContainsKey(orgs[o]["label"].ToString()))
                    {
                        if (culture == Culture.NorwegianCode)
                        {
                            Organizations.Add(orgs[o]["label"].ToString(), orgs[o]["label"].ToString());
                        }
                        else
                        {
                            Organizations.Add(orgs[o]["label"].ToString(), orgsEnglish[o]["label"].ToString());
                        }
                    }
                }

                Organizations = Organizations.OrderBy(o => o.Value).ToDictionary(o => o.Key, o => o.Value);
                memCacher.Set("organizations_" + culture, Organizations, new DateTimeOffset(DateTime.Now.AddYears(1)));
            }

            return(Organizations);
        }
示例#22
0
 public HttpResponseMessage SendToList_Routine([FromBody] NotificationModel value)
 {
     try
     {
         if (value.RecipientIDs == null || string.IsNullOrEmpty(value.Content) || value.Routine == null || value.Routine.Time == null)
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest));
         }
         IEnumerable <string> _sessionGuid;
         User _usr = new User();
         if (Request.Headers.TryGetValues("SessionGuid", out _sessionGuid))
         {
             string _sessID = _sessionGuid.First();
             if (MemoryCacher.GetValue(_sessID) == null)
             {
                 return(Request.CreateResponse(HttpStatusCode.Forbidden));
             }
             string _userID = MemoryCacher.GetValue(_sessID).ToString();
             _usr = bus_user.Get_ById(_userID);
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest));
         }
         string _webappid = value.AppIDs.Where(x => bus_AppInfo.Get_ById(x).Type == AppTypeConst.WEBAPP).FirstOrDefault();
         if (_webappid != null)
         {
             NotificationActivity _notif = bus_NotificationActivity.Create(new NotificationActivity
             {
                 Content      = value.Content,
                 UserID       = _usr.Id,
                 RecipientIDs = value.RecipientIDs,
                 AppIDs       = new List <string> {
                     _webappid
                 },
                 IsRoutine = true,
                 Routine   = value.Routine
             });
             return(Request.CreateResponse(HttpStatusCode.OK, new { NotifID = _notif.Id }));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest));
         }
     }
     catch (Exception ex)
     {
         LogGenerationHelper.WriteToFile(ex.Message);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError));
     }
 }
示例#23
0
        public IHttpActionResult GetUserSurveys(Guid projectId)
        {
            if (projectId == Guid.Empty)
            {
                return(BadRequest("project id is empty"));
            }

            var project = UnitOfWork.ProjectsRepository.Find(projectId);

            if (project == null)
            {
                return(NotFound());
            }

            var assignment = CurrentOrgUser.Assignments.SingleOrDefault(a => a.ProjectId == projectId);

            if (assignment == null || !assignment.CanView)
            {
                return(Unauthorized());
            }

            // we want records from advice threads too, so can't filter by FilledById.
            // this might need a refactoring but works for now.

            //var surveys = UnitOfWork.FilledFormsRepository.AllAsNoTracking
            //    .Where(s => s.ProjectId == projectId && s.FilledById == CurrentOrgUser.Id)
            //    .OrderByDescending(s => s.DateCreated);

            var cacheKey   = $"{CACHE_KEY}_{projectId}_{CurrentOrgUser.Id}";
            var cacheEntry = MemoryCacher.GetValue(cacheKey);

            if (cacheEntry == null)
            {
                var surveys = UnitOfWork.FilledFormsRepository
                              .AllAsNoTracking
                              .Where(s => s.ProjectId == projectId)
                              .OrderByDescending(s => s.DateCreated)
                              .ToList()
                              .Select(s => Mapper.Map <FilledFormDTO>(s))
                              .ToList();

                MemoryCacher.Add(cacheKey, surveys, DateTimeOffset.UtcNow.AddMinutes(1));

                return(Ok(surveys));
            }
            else
            {
                var result = (List <FilledFormDTO>)cacheEntry;
                return(new CachedResult <List <FilledFormDTO> >(result, TimeSpan.FromMinutes(1), this));
            }
        }
示例#24
0
        public async Task <IHttpActionResult> Get(Guid?organisationId = null)
        {
            if (CurrentUser is OrgUser)
            {
                var isTeamManager = await ServiceContext.UserManager.IsInRoleAsync(CurrentOrgUser.Id, Role.ORG_TEAM_MANAGER);

                var cacheKey   = isTeamManager ? $"{CACHE_KEY}_MANAGER_{CurrentOrgUser.Id}" : $"{CACHE_KEY}_{CurrentOrgUser.OrganisationId}";
                var cacheEntry = MemoryCacher.GetValue(cacheKey);

                if (cacheEntry == null)
                {
                    if (isTeamManager)
                    {
                        var managerTeams = TeamService.GetManagerTeams(CurrentOrgUser.Id);
                        MemoryCacher.Add(cacheKey, managerTeams, DateTimeOffset.UtcNow.AddMinutes(1));

                        return(Ok(managerTeams));
                    }
                    else
                    {
                        var teams = TeamService.Get(CurrentOrgUser.OrganisationId);
                        MemoryCacher.Add(cacheKey, teams, DateTimeOffset.UtcNow.AddMinutes(1));

                        return(Ok(teams));
                    }
                }
                else
                {
                    var result = (List <OrganisationTeamDTO>)cacheEntry;
                    return(new CachedResult <List <OrganisationTeamDTO> >(result, TimeSpan.FromMinutes(1), this));
                }
            }

            // else if current user is SuperUser or PlatformUser
            var _cacheKey   = organisationId.HasValue ? $"{CACHE_KEY}_{organisationId}" : CACHE_KEY;
            var _cacheEntry = MemoryCacher.GetValue(_cacheKey);

            if (_cacheEntry == null)
            {
                var teams = organisationId.HasValue ? TeamService.Get(organisationId) : TeamService.Get();
                MemoryCacher.Add(_cacheKey, teams, DateTimeOffset.UtcNow.AddMinutes(1));

                return(Ok(teams));
            }
            else
            {
                var retVal = (List <OrganisationTeamDTO>)_cacheEntry;
                return(new CachedResult <List <OrganisationTeamDTO> >(retVal, TimeSpan.FromMinutes(1), this));
            }
        }
示例#25
0
        public async Task <IEnumerable <Badge> > Get()
        {
            var badges = MemoryCacher.GetValue(Cache.Badges) as IEnumerable <Badge>;

            if (badges != null)
            {
                return(badges);
            }

            badges = await _databaseRepository.GetBadges();

            MemoryCacher.Add(Cache.Badges, badges);
            return(badges);
        }
示例#26
0
        public async Task <Menu> GetMenu()
        {
            Menu menu;
            var  cacheMenu = MemoryCacher.GetValue(Cache.Menu) as Menu;

            if (cacheMenu != null)
            {
                menu = cacheMenu;
            }
            else
            {
                menu = await _databaseRepository.GetEnabledMenu();
            }
            return(menu);
        }
示例#27
0
        public void LoadJson()
        {
            if ((MemoryCacher.GetValue("ProtechContext") == null))
            {
                using (StreamReader r = new StreamReader(HttpRuntime.AppDomainAppPath + "getResponse.json"))
                {
                    string             json = r.ReadToEnd();
                    var                func = JsonConvert.DeserializeObject <Funcionario>(json);
                    List <Funcionario> list = new List <Funcionario>();
                    list.Add(func);

                    MemoryCacher.Add("ProtechContext", list);
                }
            }
        }
示例#28
0
        private ListResult <PlateListItem> GetPromotional(int siteId)
        {
            ListResult <PlateListItem> data = null;

            if (base.IsUseCache)
            {
                data = MemoryCacher.GetValue("SITE-PROMOTIONAL") as ListResult <PlateListItem>;

                if (data != null)
                {
                    return(data);
                }
            }

            IList <PromotionalInfo> list = VShopHelper.GetAllPromotional(ClientType.App);

            List <PlateListItem> items = new List <PlateListItem>();

            if (list != null)
            {
                PlateListItem item = null;

                foreach (var current in list)
                {
                    item = new PlateListItem();

                    item.Id              = current.BannerId;
                    item.Title           = current.ShortDesc;
                    item.ImageUrl        = Util.AppendImageHost(current.ImageUrl);
                    item.NavigationType  = (int)current.LocationType;
                    item.Values          = current.Url;
                    item.DisplaySequence = current.DisplaySequence;

                    items.Add(item);
                }
            }

            data = new ListResult <PlateListItem>();
            data.TotalNumOfRecords = items.Count;;
            data.Results           = items;

            if (base.IsUseCache)
            {
                MemoryCacher.Add("SITE-PROMOTIONAL", data, DateTimeOffset.UtcNow.AddMinutes(SITE_CACHE_KEEP_TIME));
            }

            return(data);
        }
        public IHttpActionResult Get()
        {
            if (CurrentUser is OrgUser)
            {
                var cacheKey   = $"{CACHE_KEY}_{CurrentOrgUser.OrganisationId}";
                var cacheEntry = MemoryCacher.GetValue(cacheKey);

                if (cacheEntry == null)
                {
                    var categories = UnitOfWork.FormTemplateCategoriesRepository
                                     .AllAsNoTracking
                                     .Where(c => c.OrganisationId == CurrentOrgUser.OrganisationId)
                                     .ToList()
                                     .Select(c => Mapper.Map <FormTemplateCategoryDTO>(c))
                                     .ToList();

                    MemoryCacher.Add(cacheKey, categories, DateTimeOffset.UtcNow.AddMinutes(1));

                    return(Ok(categories));
                }
                else
                {
                    var result = (List <FormTemplateCategoryDTO>)cacheEntry;
                    return(new CachedResult <List <FormTemplateCategoryDTO> >(result, TimeSpan.FromMinutes(1), this));
                }
            }

            // else if current user is SuperUser
            var _cacheEntry = MemoryCacher.GetValue(CACHE_KEY);

            if (_cacheEntry == null)
            {
                var _categories = UnitOfWork.FormTemplateCategoriesRepository
                                  .AllAsNoTracking
                                  .ToList()
                                  .Select(c => Mapper.Map <FormTemplateCategoryDTO>(c))
                                  .ToList();

                MemoryCacher.Add(CACHE_KEY, _categories, DateTimeOffset.UtcNow.AddMinutes(1));

                return(Ok(_categories));
            }
            else
            {
                var retVal = (List <FormTemplateCategoryDTO>)_cacheEntry;
                return(new CachedResult <List <FormTemplateCategoryDTO> >(retVal, TimeSpan.FromMinutes(1), this));
            }
        }
示例#30
0
        public async Task <Menu> GetActiveMenu()
        {
            if (MemoryCacher.GetValue(Cache.Menu) is Menu cacheMenu)
            {
                return(cacheMenu);
            }

            var menu = await _databaseRepository.GetEnabledMenu();

            if (menu != null)
            {
                MemoryCacher.Add(Cache.Menu, menu);
            }

            return(menu);
        }