public TagsResponse GetById(int id) { TagsResponse response = new TagsResponse(); if (id == 0) { response.Success = false; response.Message = "TagId value empty."; } using (var context = new PersonalBlogEntities()) { try { response.Tags = context.Tags .Include("Posts") .Where(t => t.TagId == id) .ToList(); if (response.Tags.Count == 0) { response.Success = false; response.Message = "Nothing found."; return(response); } response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } } return(response); }
public async Task <IActionResult> GetAsync(string id, DateTime?realtime_start, DateTime?realtime_end, string order_by, string sort_order) { TagsResponse result = new TagsResponse(); try { api.Arguments.ApiKey = appSettings.ApiKey; api.Arguments.series_id = id; api.Arguments.realtime_start = realtime_start ?? api.Arguments.realtime_start; api.Arguments.realtime_end = realtime_end ?? api.Arguments.realtime_end; var orderBy = ParseEnum <tags_order_by_values>(order_by); api.Arguments.order_by = orderBy ?? api.Arguments.order_by; var sortOrder = ParseEnum <sort_order_values>(sort_order); api.Arguments.sort_order = sortOrder ?? api.Arguments.sort_order; result.container = await api.FetchAsync(); SetApiValues(api, result); } catch (Exception exception) { logger.LogError(exception, "GetSeriesTags failed"); return(StatusCode(500)); } return(Ok(result)); }
public TagsResponse Delete(int id) { TagsResponse response = new TagsResponse(); if (id == 0) { response.Success = false; response.Message = "Tag id was not passed or was null/default."; return(response); } try { using (var context = new PersonalBlogEntities()) { var toRemove = context.Tags.Where(t => t.TagId == id).First(); context.Tags.Remove(toRemove); context.SaveChanges(); response.Success = true; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public TagsResponse Edit(Tag tag) { TagsResponse response = new TagsResponse(); if (string.IsNullOrEmpty(tag.TagName) || tag.Posts.Count() < 1) { response.Success = false; response.Message = "Name is required, tag must be associated with at least one post."; return(response); } try { using (var context = new PersonalBlogEntities()) { var toEdit = context.Tags.Where(t => t.TagId == tag.TagId).First(); toEdit = tag; context.SaveChanges(); response.Success = true; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public TagsResponse GetAll() { TagsResponse response = new TagsResponse(); using (var context = new PersonalBlogEntities()) { try { response.Tags = context.Tags .Include("Posts") .ToList(); if (response.Tags.Count == 0) { response.Success = false; response.Message = "Nothing found."; return(response); } response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } } return(response); }
public void GetAll() { TagsResponse response = repo.GetAll(); Tag actual = response.Tags.Where(t => t.TagId == 3).First(); Assert.AreEqual(true, response.Success); Assert.AreEqual("#Neature", actual.TagName); }
public void GetAll() { TagsResponse actual = _repo.GetAll(); Assert.AreEqual(true, actual.Success); Assert.AreEqual("#MeToo", actual.Tags.Where(t => t.TagId == 1)); Assert.AreEqual("#Neature", actual.Tags.Where(t => t.TagId == 3)); }
public void Delete() { TagsResponse response = repo.Delete(1); TagsResponse actual = repo.GetById(1); Assert.AreEqual(true, response.Success); Assert.AreEqual(false, actual.Success); }
public void GetById(string expected, int id, bool valid) { TagsResponse response = repo.GetById(id); Assert.AreEqual(valid, response.Success); if (valid == true) { Tag actual = response.Tags.First(); Assert.AreEqual(expected, actual.TagName); } }
public void Add() { PostsRepo postGet = new PostsRepo(); List <Post> junkPost = new List <Post>(); junkPost.Add(postGet.GetAll().Posts.FirstOrDefault()); Tag toAdd = new Tag { TagName = "#Testerized", Posts = junkPost }; TagsResponse response = repo.Add(toAdd); Assert.AreEqual(true, response.Success); }
public TagsResponse Delete(int id) { var context = new PersonalBlogEntities(); if (context.Tags.FirstOrDefault(t => t.TagId == id) == null) { var response = new TagsResponse(); response.Success = false; response.Message = "There is no tag in our database that matches the delete criteria."; return(response); } return(repo.Delete(id)); }
public TagsResponse Edit(Tag tag) { var context = new PersonalBlogEntities(); if (context.Tags.Contains(tag)) { var response = new TagsResponse(); response.Success = false; response.Message = $"The tag {tag} already exists in the database."; response.Tags.Add(tag); return(response); } else { return(repo.Edit(tag)); } }
private IEnumerable <string> GetMixesByTag(string tag) { try { using (var session = new EightTracksSession(ApiKey)) { TagsResponse response = session.Query <Tags>().Execute(1, tag); return(response.Tags.Select(t => t.Name)); } } catch (Exception e) { Logger.Log("Error while getting 8tracks mixes. " + e.Message, Category.Exception, Priority.Medium); } return(new string[0]); }
public async Task <IActionResult> GetAsync(string series_search_text, string tag_names, DateTime?realtime_start, DateTime?realtime_end, int?limit, int?offset, string order_by, string sort_order, string exclude_tag_names, string tag_group_id, string tag_search_text) { TagsResponse result = new TagsResponse(); try { api.Arguments.ApiKey = appSettings.ApiKey; api.Arguments.series_search_text = series_search_text; api.Arguments.tag_names = tag_names; api.Arguments.realtime_start = realtime_start ?? api.Arguments.realtime_start; api.Arguments.realtime_end = realtime_end ?? api.Arguments.realtime_end; api.Arguments.limit = limit ?? api.Arguments.limit; api.Arguments.offset = offset ?? api.Arguments.offset; var orderBy = ParseEnum <tags_order_by_values>(order_by); api.Arguments.order_by = orderBy ?? api.Arguments.order_by; var sortOrder = ParseEnum <sort_order_values>(sort_order); api.Arguments.sort_order = sortOrder ?? api.Arguments.sort_order; api.Arguments.exclude_tag_names = exclude_tag_names; var tagGroupId = ParseEnum <tag_group_id_values>(tag_group_id); api.Arguments.tag_group_id = tagGroupId ?? api.Arguments.tag_group_id; api.Arguments.tag_search_text = tag_search_text ?? api.Arguments.tag_search_text; result.container = await api.FetchAsync(); SetApiValues(api, result); } catch (Exception exception) { logger.LogError(exception, "GetSeriesSearchRelatedTags failed"); return(StatusCode(500)); } return(Ok(result)); }
public TagsResponse GetById(int id) { var context = new PersonalBlogEntities(); if (id == 0) { return(repo.GetById(id)); } if (context.Tags.FirstOrDefault(t => t.TagId == id) == null) { var response = new TagsResponse(); response.Success = false; response.Message = "That tag is not valid."; return(response); } return(repo.GetById(id)); }
public void Edit() { PostsRepo postGet = new PostsRepo(); List <Post> junkPost = new List <Post>(); junkPost.Add(postGet.GetAll().Posts.FirstOrDefault()); Tag toAdd = new Tag { TagName = "#Testerized", Posts = junkPost }; repo.Add(toAdd); Tag toEdit = repo.GetByName("#Testerized") .Tags.First(); toEdit.TagName = "#MrTsTea"; TagsResponse response = repo.Edit(toEdit); Assert.AreEqual(true, response.Success); }
public TagsResponse GetByName(string tag) { var context = new PersonalBlogEntities(); if (string.IsNullOrEmpty(tag)) { return(repo.GetByName(tag)); } if (context.Tags.FirstOrDefault(p => p.TagName == tag) == null) { var response = new TagsResponse(); response.Success = false; response.Message = $"There are no posts with the tag {tag}."; return(response); } else { return(repo.GetByName(tag)); } }
private BaseResponse HandleGetMyTags(DynamicDictionary _parameters) { User user; BaseResponse response; if (AuthHelper.IsAuthorized(Request, out user)) { int page = _parameters["page"]; int pageSize = _parameters["pagesize"]; HydrantWikiManager hwm = new HydrantWikiManager(); List <Tag> tags = hwm.GetTagsForUser(user.Guid, page, pageSize); List <Objects.Tag> outputTags = new List <Objects.Tag>(); foreach (Tag tag in tags) { Objects.Tag outputTag = new Objects.Tag(tag); outputTags.Add(outputTag); } int count = hwm.GetTagCount(user.Guid); int pages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(count) / Convert.ToDouble(pageSize))); response = new TagsResponse(outputTags, page, pageSize, pages, count); } else { LogUnauthorized(Request); response = new BaseResponse { Success = false, Error = "Unauthorized", Message = "Reauthenticate" }; } return(response); }
public TagsResponse GetByName(string tag) { TagsResponse response = new TagsResponse(); if (string.IsNullOrEmpty(tag)) { response.Success = false; response.Message = "Tag value empty."; return(response); } using (var context = new PersonalBlogEntities()) { try { response.Tags = context.Tags .Include("Posts") .Where(t => (t.TagName.ToLower()).Contains(tag.ToLower())) .ToList(); if (response.Tags.Count == 0) { response.Success = false; response.Message = "Nothing found."; return(response); } response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } } return(response); }