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); }
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); }
public ActionResult _MergeTag() { TagViewModel viewModel = new TagViewModel(); GetTagListResponse response = tagService.GetTagsBasedonaccount(UserExtensions.ToAccountID(this.Identity)); viewModel.Tags = response.Tags; return(PartialView("_MergeTag", viewModel)); }
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)); }
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)); }
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); }
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); }
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); }
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)); }
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)); }
public JsonResult GetTags() { GetTagListResponse response = tagService.GetTagsBasedonaccount(UserExtensions.ToAccountID(this.Identity)); return(Json(new { success = true, response.Tags }, JsonRequestBehavior.AllowGet)); }