예제 #1
0
        public GetTagListResponse GetAllTags(GetTagListRequest request)
        {
            Logger.Current.Verbose("Request to fetch all the tags.");
            GetTagListResponse response = new GetTagListResponse();

            if (request.SortField != null)
            {
                var maps = SmartTouch.CRM.ApplicationServices.ObjectMappers.MapperConfigurationProvider.Instance.FindTypeMapFor <TagViewModel, Tag>();

                foreach (var propertyMap in maps.GetPropertyMaps())
                {
                    if (request.SortField.Equals(propertyMap.SourceMember.Name))
                    {
                        request.SortField = propertyMap.DestinationProperty.MemberInfo.Name;
                        break;
                    }
                }
            }
            IEnumerable <Tag> tags = tagRepository.FindAll(request.Limit, request.PageNumber, request.Name, request.AccountId, request.SortField, request.SortDirection).ToList();

            if (tags == null)
            {
                response.Exception = GetTagNotFoundException();
            }
            else
            {
                response.TotalHits = (tags != null && tags.Any()) ? tags.FirstOrDefault().TotalTagCount : 0;
                response.Tags      = Mapper.Map <IEnumerable <Tag>, IEnumerable <TagViewModel> >(tags);
            }
            return(response);
        }
예제 #2
0
        public GetTagListResponse GetAllTagsByContacts(GetTagListRequest request)
        {
            Logger.Current.Verbose("Request to fetch all the tags.");
            GetTagListResponse response = new GetTagListResponse();
            int TotalHits = default(int);

            if (request.SortField != null)
            {
                var maps = SmartTouch.CRM.ApplicationServices.ObjectMappers.MapperConfigurationProvider.Instance.FindTypeMapFor <TagViewModel, Tag>();

                foreach (var propertyMap in maps.GetPropertyMaps())
                {
                    if (request.SortField.Equals(propertyMap.SourceMember.Name))
                    {
                        request.SortField = propertyMap.DestinationProperty.MemberInfo.Name;
                        break;
                    }
                }
            }
            bool isAccountAdmin    = CheckingDataSharing(request.RoleId, request.AccountId, request.IsSTadmin);
            IEnumerable <Tag> tags = tagRepository.AllTagsByContacts(request.Name, request.Limit, request.PageNumber, request.AccountId, isAccountAdmin, request.RequestedBy.Value, out TotalHits, request.AccountId, request.SortField, request.SortDirection);

            if (tags == null)
            {
                response.Exception = GetTagNotFoundException();
            }
            else
            {
                IEnumerable <TagViewModel> list = Mapper.Map <IEnumerable <Tag>, IEnumerable <TagViewModel> >(tags);
                response.Tags      = list;
                response.TotalHits = TotalHits;
            }
            return(response);
        }
예제 #3
0
        public ActionResult _MergeTag()
        {
            TagViewModel       viewModel = new TagViewModel();
            GetTagListResponse response  = tagService.GetTagsBasedonaccount(UserExtensions.ToAccountID(this.Identity));

            viewModel.Tags = response.Tags;
            return(PartialView("_MergeTag", viewModel));
        }
예제 #4
0
        public HttpResponseMessage GetRecentPopularTags()
        {
            GetTagListResponse response = new GetTagListResponse();
            var tags = tagService.GetRecentAndPopularTags(new GetRecentAndPopularTagsRequest()
            {
                AccountId = this.AccountId
            });

            response.PopularTags = tags.PopularTags;
            response.RecentTags  = tags.RecentTags;
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
예제 #5
0
        public ActionResult _MergeTagModal(int tagId)
        {
            GetTagResponse     response    = tagService.GetTag(new GetTagRequest(tagId));
            TagViewModel       viewModel   = new TagViewModel();
            GetTagListResponse tagresponse = tagService.GetTagsBasedonaccount(UserExtensions.ToAccountID(this.Identity));

            viewModel.Tags          = tagresponse.Tags;
            viewModel.sourceTagID   = tagId;
            viewModel.sourceTagName = response.TagViewModel.TagName;
            viewModel.Count         = response.TagViewModel.Count;
            ViewBag.IsModal         = true;
            return(PartialView("_MergeTag", viewModel));
        }
예제 #6
0
        public void GetAllTags_RunTimeException_ExceptionDetails()
        {
            mockTagRepository.Setup(cr => cr.Search(It.IsAny <string>())).Throws(new InvalidOperationException());

            GetTagListResponse response = tagService.GetAllTags(new GetTagListRequest()
            {
                Name = ""
            });

            mockRepository.VerifyAll();
            Assert.AreEqual(typeof(InvalidOperationException), response.Exception.GetType());
            Assert.AreNotEqual(null, response.Exception);
        }
예제 #7
0
        public void GetAllTags_ValidTags_Succeed()
        {
            var mockTags = TagMockData.GetMockTags(mockRepository, 10).ToList();

            mockTagRepository.Setup(cr => cr.Search(It.IsAny <string>())).Returns(mockTags);

            GetTagListResponse response = tagService.GetAllTags(new GetTagListRequest()
            {
                Name = ""
            });
            ITagsListViewModel viewModel = response.TagsListViewModel;

            mockRepository.VerifyAll();
            Assert.AreEqual(mockTags.Count, viewModel.Tags.Count());
            Assert.AreEqual(null, response.Exception);
        }
예제 #8
0
        public GetTagListResponse GetTagsBasedonaccount(int accountId)
        {
            Logger.Current.Verbose("Request to fetch all the tags.");
            GetTagListResponse response = new GetTagListResponse();
            IEnumerable <Tag>  tags     = tagRepository.FindAll(accountId);

            if (tags == null)
            {
                response.Exception = GetTagNotFoundException();
            }
            else
            {
                IEnumerable <TagViewModel> list = Mapper.Map <IEnumerable <Tag>, IEnumerable <TagViewModel> >(tags);
                response.Tags = list;
            }

            return(response);
        }
예제 #9
0
        public ActionResult TagsViewRead([DataSourceRequest] DataSourceRequest request, string name)
        {
            string             sortField = request.Sorts.Count > 0 ? request.Sorts.First().Member :null;
            var                direction = request.Sorts.Count > 0 ? request.Sorts.First().SortDirection : System.ComponentModel.ListSortDirection.Descending;
            GetTagListResponse response  = tagService.GetAllTags(new GetTagListRequest()
            {
                Name          = name,
                Limit         = request.PageSize,
                PageNumber    = request.Page,
                AccountId     = UserExtensions.ToAccountID(this.Identity),
                SortField     = sortField,
                SortDirection = direction
            });

            return(Json(new DataSourceResult
            {
                Data = response.Tags,
                Total = response.TotalHits
            }, JsonRequestBehavior.AllowGet));
        }
예제 #10
0
        public ActionResult GetRecentPopularTags(string tagList)
        {
            int[] myInts = new int[] { };
            if (!String.IsNullOrEmpty(tagList))
            {
                string[] array = tagList.Split(',');
                myInts = array.Select(int.Parse).ToArray();
            }

            GetTagListResponse  response            = new GetTagListResponse();
            PopularTagsResponse popularTagsResponse = tagService.GetPopularTags(new PopularTagsRequest()
            {
                AccountId = this.Identity.ToAccountID(), TagsList = myInts, Limit = 10
            });

            if (popularTagsResponse.TagsViewModel != null)
            {
                response.PopularTags = popularTagsResponse.TagsViewModel;
            }
            else
            {
                response.PopularTags = null;
            }

            RecentTagsResponse recentTagsResponse = tagService.GetRecentTags(new RecentTagsRequest()
            {
                AccountId = this.Identity.ToAccountID(), TagsList = myInts, Limit = 10
            });

            if (recentTagsResponse.TagsViewModel != null)
            {
                response.RecentTags = recentTagsResponse.TagsViewModel;
            }

            return(Json(new { success = true, response }, JsonRequestBehavior.AllowGet));
        }
예제 #11
0
        public JsonResult GetTags()
        {
            GetTagListResponse response = tagService.GetTagsBasedonaccount(UserExtensions.ToAccountID(this.Identity));

            return(Json(new { success = true, response.Tags }, JsonRequestBehavior.AllowGet));
        }