public Result Get(int id) { var con = new DapperConnectionManager(); var query = new QueryEntity(); query.Query = @"SELECT a.ArticleId, a.Name as ArticleName, a.Title as ArticleTitle, a.CategoryId, a.Published, a.Type as ArticleType, c.Name, c.Title, c.Type, c.ContentItemId, c.Position, c.Text from Articles as a LEFT JOIN ContentItems as c on a.ArticleId = c.ArticleId where a.ArticleId = @ArticleId and a.Active = 1 ORDER BY c.Position ASC"; query.Entity = new { ArticleId = id }; var result = con.ExecuteQuery(query); if (!result.Success) { result.Message = "Article not found"; return(result); } var r = (IEnumerable <dynamic>)result.Entity; if (!r.Any()) { return(result); } var f = r.First(); var articleEntity = new ArticleEntity(); articleEntity.ArticleId = f.ArticleId; articleEntity.Name = f.ArticleName; articleEntity.Title = f.ArticleTitle; articleEntity.CategoryId = f.CategoryId; articleEntity.Published = f.Published; articleEntity.Type = f.ArticleType; articleEntity.ContentItems = new List <ContentItemEntity>(); foreach (var item in r) { if (item.ContentItemId == null) { continue; } var contentItem = new ContentItemEntity { Name = item.Name, ContentItemId = item.ContentItemId, Text = item.Text, Position = item.Position, Type = item.Type, ArticleId = item.ArticleId, Title = item.Title, TextShort = (item.Text as string ?? string.Empty).Truncate() }; articleEntity.ContentItems.Add(contentItem); } result.Entity = articleEntity; return(result); }
public Result Get(int id) { var con = new DapperConnectionManager(); var query = new QueryEntity(); query.Query = @"SELECT s.SectionId, s.Name as SectionName, s.Title as SectionTitle, c.Name, c.Title, c.Type, c.ContentItemId, c.Position, c.Text from Sections as s LEFT JOIN ContentItems as c on s.SectionId = c.SectionId where s.SectionId = @SectionId ORDER BY c.Position ASC"; query.Entity = new { SectionId = id }; var result = con.ExecuteQuery(query); if (!result.Success) { result.Message = "Section not found"; return(result); } var r = (IEnumerable <dynamic>)result.Entity; if (!r.Any()) { return(result); } var sectionEntity = new SectionEntity(); sectionEntity.SectionId = r.First().SectionId; sectionEntity.Name = r.First().SectionName; sectionEntity.Title = r.First().SectionTitle; sectionEntity.ContentItems = new List <ContentItemEntity>(); foreach (var item in r) { if (item.ContentItemId == null) { continue; } var contentItem = new ContentItemEntity { Name = item.Name, ContentItemId = item.ContentItemId, Text = item.Text, Position = item.Position, Type = item.Type, SectionId = item.SectionId, Title = item.Title, TextShort = (item.Text as string ?? string.Empty).Truncate() }; sectionEntity.ContentItems.Add(contentItem); } result.Entity = sectionEntity; return(result); }
public Result Update(ContentItemEntity entity) { var con = new DapperConnectionManager(); ImageManager imageManager = new ImageManager(); if (entity.ImagePosted != null) { var resImgCheck = imageManager.CheckFileImageAndSave(entity.ImagePath, entity.ImagePosted, 30, 30, 3000, 3000); if (!resImgCheck.Success) { return(resImgCheck); } entity.Image = resImgCheck.Entity.ToString(); } if (entity.TitleImagePosted != null) { var resImgCheck = imageManager.CheckFileImageAndSave(entity.ImagePath, entity.TitleImagePosted, 30, 30, 3000, 3000); if (!resImgCheck.Success) { return(resImgCheck); } entity.TitleImage = resImgCheck.Entity.ToString(); } var query = new QueryEntity(); query.Entity = entity; query.Query = @"UPDATE ContentItems set Name=@Name, Title=@Title, SectionId=@SectionId, ArticleId=@ArticleId, Text=@Text, Type=@Type, Image=@Image, Carousel=@Carousel, Link=@Link, ButtonLink=@ButtonLink, Video=@Video, TitleImage = @TitleImage WHERE ContentItemId = @ContentItemId"; var result = con.ExecuteQuery(query); result.Message = result.Success ? "The content item has been updated" : "An error occurred"; result.Entity = entity.ContentItemId; return(result); }
private List <ArticleEntity> FormatArticles(IEnumerable <dynamic> sections) { var list = new List <ArticleEntity>(); foreach (var item in sections) { ArticleEntity entity = list.FirstOrDefault(x => x.ArticleId == item.ArticleId); if (entity == null) { entity = new ArticleEntity(); entity.ArticleId = item.ArticleId; entity.Name = item.ArticleName; entity.Title = item.ArticleTitle; entity.CategoryId = item.CategoryId; entity.CategoryName = item.CategoryName; entity.Date = item.Date; entity.DateFormatted = item.Date.ToString("d MMM yyyy"); entity.ContentItems = new List <ContentItemEntity>(); list.Add(entity); } if (item.ContentItemId == null) { continue; } var contentItem = new ContentItemEntity { Name = item.Name, ContentItemId = item.ContentItemId, Text = item.Text, Position = item.Position, Type = item.Type, SectionId = item.SectionId, Title = item.Title, ButtonLink = item.ButtonLink, Image = item.Image, Carousel = item.Carousel, TitleImage = item.TitleImage, Video = item.Video, Link = item.Link }; entity.ContentItems.Add(contentItem); } return(list); }
private List <SectionEntity> FormatSections(IEnumerable <dynamic> sections) { var sectionsList = new List <SectionEntity>(); foreach (var item in sections) { SectionEntity sectionEntity = sectionsList.FirstOrDefault(x => x.SectionId == item.SectionId); if (sectionEntity == null) { sectionEntity = new SectionEntity(); sectionEntity.SectionId = item.SectionId; sectionEntity.Name = item.SectionName; sectionEntity.Title = item.SectionTitle; sectionEntity.ContentItems = new List <ContentItemEntity>(); sectionsList.Add(sectionEntity); } if (item.ContentItemId == null) { continue; } var contentItem = new ContentItemEntity { Name = item.Name, ContentItemId = item.ContentItemId, Text = item.Text, Position = item.Position, Type = item.Type, SectionId = item.SectionId, Title = item.Title, ButtonLink = item.ButtonLink, Image = item.Image, Carousel = item.Carousel, TitleImage = item.TitleImage, Video = item.Video, Link = item.Link }; sectionEntity.ContentItems.Add(contentItem); } return(sectionsList); }
public Result Insert(ContentItemEntity entity) { var con = new DapperConnectionManager(); ImageManager imageManager = new ImageManager(); if (entity.ImagePosted != null) { var resImgCheck = imageManager.CheckFileImageAndSave(entity.ImagePath, entity.ImagePosted, 30, 30, 3000, 3000); if (!resImgCheck.Success) { return(resImgCheck); } entity.Image = resImgCheck.Entity.ToString(); } if (entity.TitleImagePosted != null) { var resImgCheck = imageManager.CheckFileImageAndSave(entity.ImagePath, entity.TitleImagePosted, 30, 30, 3000, 3000); if (!resImgCheck.Success) { return(resImgCheck); } entity.TitleImage = resImgCheck.Entity.ToString(); } var query = new QueryEntity(); query.Entity = entity; query.Query = @"INSERT INTO ContentItems ( Name, Title, Position, SectionId, ArticleId, Text, Type, Image, Carousel, Link, ButtonLink, Video, TitleImage) VALUES( @Name, @Title, @Position, @SectionId, @ArticleId, @Text, @Type, @Image, @Carousel, @Link, @ButtonLink, @Video, @TitleImage )"; var result = con.InsertQuery(query); result.Message = result.Success ? "The content item has been created" : "An error occurred"; return(result); }