public async Task <UrlForVisitModel> GetURLForVisit(UrlForVisitModel Model)
        {
            return(await ExceptionHandler.CallMethod(async() =>
            {
                var DashboardService = new DashboardService();
                UrlForVisitModel result = null;
                if (DashboardService.CheckUrlVisit(Model, User.Identity.GetUserId()))
                {
                    if (Model.URLAddress != null)
                    {
                        DashboardService.AddUrlVisit(Model, User.Identity.GetUserId());
                    }

                    var role = ((ClaimsIdentity)User.Identity).Claims
                               .Where(c => c.Type == ClaimTypes.Role)
                               .Select(c => c.Value)
                               .FirstOrDefault();

                    if (role == "Admin")
                    {
                        result = DashboardService.GetAdminURLForVisit(User.Identity.GetUserId(), Model.Duration, Model.Count, Model.Mobile);
                    }
                    else
                    {
                        result = DashboardService.GetURLForVisit(User.Identity.GetUserId(), Model.Duration, Model.Count, Model.Mobile);
                    }
                }
                return result;
            }));
        }
Пример #2
0
        public bool CheckUrlVisit(UrlForVisitModel Url, string UserId)
        {
            var UrlVisit = _dbUrlVisit.Repository.GetAsQuerable().Where(x => x.URLId == Url.id && x.VisitedBy == UserId &&
                                                                        DbFunctions.TruncateTime(x.VisitedOn) == DbFunctions.TruncateTime(DateTime.Now)).FirstOrDefault();

            if (UrlVisit == null)
            {
                return(true);
            }
            return(false);
        }
Пример #3
0
        public void AddUrlVisit(UrlForVisitModel Url, string UserId)
        {
            var UrlVisit = new URLVisit
            {
                URLId     = Url.id,
                VisitedBy = UserId,
                VisitedOn = DateTime.Now
            };

            _dbUrlVisit.Repository.Insert(UrlVisit);
            _dbUrlVisit.Save();
        }