public ContentDTO SaveContent(ContentDTO contentDto) { using (ISession session = HibernateHelper.GetSession().OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { Content content = new Content(); Mapper.CreateMap<ContentDTO, Content>(); //Mappo la Content in ContentDTO content = Mapper.Map<ContentDTO, Content>(contentDto); HibernateHelper.Persist(content, session); //Rimappo l'oggetto da restituire Mapper.CreateMap<Content, ContentDTO>(); //Mappo la ContentDTO in Content contentDto = Mapper.Map<Content, ContentDTO>(content); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { session.Flush(); session.Close(); } } } return contentDto; }
private Content MapToContent(ContentDTO contentDTO, Content content) { content.ContentString = contentDTO.ContentString; content.Title = contentDTO.Title; content.UpdateTime = DateTime.Now; return(content); }
public async Task <IActionResult> PatchContent(int id, [FromBody] JsonPatchDocument <ContentDTO> patchModel) { var user = await _userManager.GetUserAsync(HttpContext.User); if (user == null || (await _userManager.IsInRoleAsync(user, Role.Admin) == false)) { return(Unauthorized("Error updating content because of incorrect authority level.")); } try { Content content = await _context.Contents.Where(x => x.ContentId == id).FirstOrDefaultAsync(); if (content == null) { return(NotFound()); } ContentDTO contentDTO = ConvertToContentDTO(content); patchModel.ApplyTo(contentDTO); content = MapToContent(contentDTO, content); _context.Contents.Update(content); await _context.SaveChangesAsync(); return(new ObjectResult(ConvertToContentDTO(content))); } catch (Exception e) { } return(BadRequest("Error updating content")); }
public ContentDTO SaveArticle([FromBody] ContentDTO art) { Content article; if (art.Id != 0) { article = context.Content.FirstOrDefault(c => c.Id == art.Id); } else { article = new Content(); context.Content.Add(article); } if (article == null) { return(null); } article.SiteId = art.SiteId; article.Title = art.Title; article.Body = art.Body; article.Type = art.Type; context.SaveChanges(); art.Id = article.Id; return(art); }
public ContentDTO GetContent() { ContentDTO result = new ContentDTO() { ID = _ContentEntity.ID, Description = _ContentEntity.Description, Episode = _ContentEntity.Episode, InWatchList = _ContentEntity.InWatchList, ReleaseDate = _ContentEntity.ReleaseDate, Season = _ContentEntity.Season, Title = _ContentEntity.Title, Poster = _ContentEntity.Poster, Trailer = _ContentEntity.Trailer, Type = _ContentEntity.Type, Video = _ContentEntity.Video, Genres = _GenreEntity.Where(p => p.ContentID == _ContentEntity.ID).Select(p => new GenreDTO() { ID = p.ID, Description = p.Description, Name = p.Name }).ToList(), Persons = _PersonEntity.Where(p => p.ContentID == _ContentEntity.ID).Select(p => new PersonDTO() { ID = p.ID, Bio = p.Bio, BornDate = p.BornDate, FirstName = p.FirstName, LastName = p.LastName, Position = p.Position }).ToList(), }; return(result); }
public IActionResult UpdateContent(ContentDTO contentDTO) //Product->BarcodeId && Language-> LanguageCode is necessary { var apiJsonResponse = new ApiJsonResponse(); try { if (contentDTO != null) { using (FoodInfoServiceContext context = new FoodInfoServiceContext()) { if (context.ProductContents.Any(x => x.Product.BarcodeId == contentDTO.Product.BarcodeId && x.Language.LanguageCode == contentDTO.Language.LanguageCode && x.IsDeleted == false)) { if (contentDTO.NutritionFact != null) { var content = context.ProductContents.Where(x => x.Product.BarcodeId == contentDTO.Product.BarcodeId && x.Language.LanguageCode == contentDTO.Language.LanguageCode && x.IsDeleted == false).FirstOrDefault(); contentDTO.NutritionFact.ID = 0; content.NutritionFact = Mapper.Map <NutritionFacts>(contentDTO.NutritionFact); content.CookingTips = contentDTO.CookingTips; content.Details = contentDTO.Details; content.Ingredients = contentDTO.Ingredients; content.Language = Mapper.Map <Language>(contentDTO.Language); content.Recommendations = contentDTO.Recommendations; content.VideoURL = contentDTO.VideoURL; content.Warnings = contentDTO.Warnings; content.ModifiedDate = DateTime.Now; if (contentDTO.ModifiedUserId == null) { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ModifiedUserIdRequired)); } content.ModifiedUserId = contentDTO.ModifiedUserId; context.SaveChanges(); return(apiJsonResponse.ApiOkContentResult(contentDTO)); } else { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage)); } } else { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage)); } } } else { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage)); } } catch (Exception ex) { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage)); } }
protected override List <ContentRevisionDTO> GetContentsPerPage(int page) { var contentrevisionList = new List <ContentRevisionDTO>(); var todayhumor = webGetutf.Load("http://m.todayhumor.co.kr/list.php?table=bestofbest&page=" + page); //사이트 이름 var todayhumor_contentscount = 0; if (todayhumor.DocumentNode.SelectNodes("//a[@href]") != null) { foreach (var todayhumor_a in todayhumor.DocumentNode.SelectNodes("//a[@href]")) { var content = new ContentDTO(); DateTime time = DateTime.Now; todayhumor_contentscount++; if (todayhumor_contentscount > 6 && todayhumor_contentscount < 27) { var todayhumor_article = todayhumor_a.Descendants().SingleOrDefault(p => p.GetAttributeValue("class", "dd") == "listSubject"); //var commentCount = todayhumor_article.SelectNodes("./span[@class = 'list_comment_count']").SingleOrDefault(); //if (commentCount != null) //{ // commentCount.Remove(); //} var article = todayhumor_article.InnerText.Trim(); HtmlAttribute todayhumor_url = todayhumor_a.Attributes["href"]; //url var url = ("http://m.todayhumor.co.kr/" + todayhumor_url.Value); var url_params = todayhumor_url.Value; contentrevisionList.Add(new ContentRevisionDTO { Crawled = DateTime.Now, isDepricate = false, For_BoardId = 9, Content = new ContentDTO { Article = article, Contents_URL = url, Url_Params = url_params, Checksum = Convert.ToBase64String(HashHelper.ObjectToMD5Hash(url_params)) } }); } } return(contentrevisionList); } else { Console.Write("9번 홈페이지에 문제가 있습니다. 확인 바랍니다."); return(null); } }
public async ThreadTask.Task <List <SectionDTO> > GetTasksForPlanAsync(int planId) { var plan = await db.Plans.Get(planId); if (plan == null) { return(null); } var sections = await db.PlanTasks.GetAll(); var section = sections .Where(pt => pt.Plan_Id == planId) .GroupBy(s => s.Sections) .Select(p => new { Id = p.Key.Id, Name = p.Key.Name, Tasks = p.Key.PlanTasks .Where(pt => pt.Plan_Id == planId) .Select(pt => pt.Tasks) }).ToList(); List <SectionDTO> sectionDTOs = new List <SectionDTO>(); foreach (var sec in section) { List <TaskDTO> taskDTOs = new List <TaskDTO>(); ContentDTO contentDTO = new ContentDTO(); foreach (var task in sec.Tasks) { var toAdd = new TaskDTO(task.Id, task.Name, task.Description, task.Private, task.Create_Id, await db.Users.ExtractFullNameAsync(task.Create_Id), task.Mod_Id, await db.Users.ExtractFullNameAsync(task.Mod_Id), task.Create_Date, task.Mod_Date, await db.PlanTasks.GetTaskPriorityInPlanAsync(task.Id, planId), await db.PlanTasks.GetTaskSectionIdInPlanAsync(task.Id, planId), await db.PlanTasks.GetIdByTaskAndPlanAsync(task.Id, planId), task.Youtube_Url); taskDTOs.Add(toAdd); } contentDTO.Tasks = taskDTOs; SectionDTO sectionDTO = new SectionDTO() { Id = sec.Id, Name = sec.Name, Content = contentDTO }; sectionDTOs.Add(sectionDTO); } return(sectionDTOs); }
public async Task <IHttpActionResult> Update(ContentDTO area) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _cdtRepo.UpdateContent(area); return(Ok()); }
public async Task <IHttpActionResult> Add(ContentDTO area) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var id = await _cdtRepo.AddContent(area); return(Ok(id)); }
public async Task <int> AddContent(ContentDTO content) { var dbContent = Mapper.Map <ContentDTO, Content>(content); _dataContext.Contents.Add(dbContent); await _dataContext.SaveChangesAsync(); await AddContentTexts(dbContent.Id, content.ContentTexts); return(dbContent.Id); }
public void SetPath(ContentDTO contentDTO) { if (contentDTO.PageContentId > 0) { BLL.BLContent.SetPath(exportPath, contentDTO); } else { BLL.BLPage.SetPath(exportPath, contentDTO); } }
public string getContentLazyFiles(ContentDTO contentDTO, string files, LayoutDTO layoutDTO) { List <string> tileNames = Parser.getPlaceHolderList(layoutDTO.TokenizeString, Constant.pattern); string str = ""; List <string> listStr = contentEntity.getContentLazyFiles(contentDTO.ContentId, tileNames); foreach (var file in listStr) { str += "," + file; } return(Parser.clearExtraComa(files + "," + str)); }
public void A_CreateContent() { content = new ContentDTO(); content.IsNew = true; content.Title = "Nuovo Content Move"; content.Skinid = 1; content = csvc.SaveContent(content); Assert.IsTrue(content.IsPersisted, "Il content non risulta salvato: isPersisted is False!"); Assert.IsTrue(content.Contentid > 0, "Il content non ha un identificativo proprio!"); }
public void TestMethodSaveContentInfo() { ContentDTO contentDTO = BLL.BLContent.getContentInfo(1); contentDTO.ContentName = "Approve1"; BLL.BLContent.saveContentInfo(contentDTO); contentDTO = BLL.BLContent.getContentInfo(1); Assert.AreEqual(contentDTO.ContentName, "Approve1"); contentDTO = BLL.BLContent.getContentInfo(1); contentDTO.ContentName = "Approve"; BLL.BLContent.saveContentInfo(contentDTO); Assert.AreEqual(contentDTO.ContentName, "Approve"); }
public async Task <IActionResult> PostAsync([FromBody] ContentDTO value) { try { var dbValue = await ContentRepository.Create(Mapper.Map <Content>(value)); return(Ok(Mapper.Map <ContentDTO>(dbValue))); } catch (System.Exception e) { return(BadRequest(e.ToString())); } }
//private string replaceCurrentPage(decimal pageId, decimal pageContentId) //{ // mainResult = mainResult.Replace("<<<pageId>>>", pageId.ToString()); // mainResult = mainResult.Replace("<<<pageContentId>>>", pageContentId.ToString()); // mainResult = mainResult.Replace("<<<rand>>>", (new Random()).Next().ToString()); // return mainResult; //} private string generateContentDesigns(decimal projectId, decimal pageId, string contentResult, ContentDTO contentDTO) { string files = "'" + contentDTO.FullPath + ".js?r=" + (new Random()).Next().ToString() + "'"; string includeList = ""; void createNextDesign(decimal designId) { List <DesignResultDTO> designResultDTOList = BLL.BLDesign.getDesignResultList(designId); foreach (DesignResultDTO designResultDTO in designResultDTOList) { if (designResultDTO.DestDesignId != null) { files += ",'Design/design" + designResultDTO.DestDesignId + ".js?r=" + (new Random()).Next().ToString() + "'"; includeList += "<div ng-controller=\"Design_" + designResultDTO.DestDesignId + "\"></div>\n"; createNextDesign(designResultDTO.DestDesignId.Value); } } } List <DesignDTO> designDTOs = BLL.BLDesign.getDesignListForPageContent(contentDTO.PageContentId); foreach (DesignDTO designDto in designDTOs) { files += ",'Design/design" + designDto.DesignId + ".js?r=" + (new Random()).Next().ToString() + "'"; includeList += "<div ng-controller=\"Design_" + designDto.DesignId + "\"></div>\n"; if (designDto.isMulipledest == 1) { createNextDesign(designDto.DesignId); } } TemplateTypeDTO PageContentTemplate = BLL.BLTemplateType.getTypeByName("PageContent"); string formName = BLL.BLPage.getPageToken(projectId, pageId, "FormName"); contentDTO = BLL.BLPageContent.getContent(contentDTO.PageContentId); files = BLL.BLContent.getContentLazyFiles(contentDTO, files, layoutDTO); PageContentTemplate.TokenizeString = PageContentTemplate.TokenizeString.Replace("<<<files>>>", files); PageContentTemplate.TokenizeString = PageContentTemplate.TokenizeString.Replace("<<<PageContentId>>>", contentDTO.PageContentId.ToString()); PageContentTemplate.TokenizeString = PageContentTemplate.TokenizeString.Replace("<<<FormName>>>", formName); PageContentTemplate.TokenizeString = PageContentTemplate.TokenizeString.Replace("<<<includeList>>>", includeList); PageContentTemplate.TokenizeString = PageContentTemplate.TokenizeString.Replace("<<<contentResult>>>", contentResult); //contentResult = "<div oc-lazy-load=\"{name:'myApp',files:[" + files + "]}\"> \n" + // "\t"+includeList + // "\t\t<div ng-controller=\"Ctrl" + contentDTO.PageContentId + "\">\n \t" + contentResult + " \n </div>\n" + // "\t\t</div> \n" + // "\t</div> \n" + // "</div> \n"; return(PageContentTemplate.TokenizeString); }
public string getControllerClick(ContentDTO contentDTO) { string str = ""; List <NavigationDTO> navigationList = getNavigationList(contentDTO.PageContentId); foreach (NavigationDTO navigationDTO in navigationList) { str += "\n"; str += "$scope.makeDesign_" + navigationDTO.ComponentId + " = function(param){ \n"; str += "\t $rootScope.design_" + navigationDTO.DestDesignId + "($scope,param); \n"; str += "} \n"; } return(str); }
public async Task <int> UpdateContent(ContentDTO content) { var existing = await _dataContext.Contents.FirstOrDefaultAsync(x => x.Id == content.Id); if (existing == null) { return(await AddContent(content)); } Mapper.Map(content, existing); _dataContext.Entry(content).State = EntityState.Modified; _dataContext.ContentTexts.RemoveRange(_dataContext.ContentTexts.Where(x => x.ParentContentId == content.Id)); await AddContentTexts(existing.Id, content.ContentTexts); await _dataContext.SaveChangesAsync(); return(content.Id); }
private string replaceLayouutComponent(decimal sourcePageContentId, ContentDTO contentDTO, LayoutDTO layoutDTO) { string contentResult = layoutDTO.TokenizeString; List <string> placeHolderList = Parser.getPlaceHolderList(contentResult, Constant.pattern); foreach (string placeHolder in placeHolderList) { List <ComponentDTO> tileComponentList = BLL.BLComponent.getComponentList(contentDTO.ContentId, Parser.clean(placeHolder)); string tileComponentStr = ""; foreach (ComponentDTO componentDTO in tileComponentList) { tileComponentStr += "\n" + BLL.BLComponent.renderComponent(componentDTO, sourcePageContentId); } contentResult = contentResult.Replace(placeHolder, tileComponentStr); } return(contentResult); }
protected override List <ContentRevisionDTO> GetContentsPerPage(int page) { try { var contentrevisionList = new List <ContentRevisionDTO>(); var cook = webGetutf.Load("http://www.82cook.com/entiz/enti.php?bn=15&cn=&searchType=&search1=&keys=%2A&page=" + page); var cook_licount = 0; foreach (var cook_div in cook.DocumentNode.SelectNodes("//td[@class= 'title']")) { var content = new ContentDTO(); cook_licount++; if (cook_licount > 3) { var anchortag = cook_div.ChildNodes.SingleOrDefault(c => c.Name.Equals("a")); var url = new Uri(new Uri("http://www.82cook.com/entiz/"), HttpUtility.HtmlDecode(anchortag.GetAttributeValue("href", "undefined"))); var Article = cook_div.InnerText.Trim(); var url_parmas = url.Query; contentrevisionList.Add(new ContentRevisionDTO { Crawled = DateTime.Now, isDepricate = false, For_BoardId = 3, Content = new ContentDTO { Article = Article, Contents_URL = url.AbsoluteUri, Url_Params = url.PathAndQuery, Checksum = Convert.ToBase64String(HashHelper.ObjectToMD5Hash(url.PathAndQuery)) } }); } } return(contentrevisionList); } catch (Exception e) { return(null); } }
public IScreen UploadImage(ContentDTO contentDTO) { string base64Array = Convert.ToBase64String(contentDTO.Content); LinkGenerator linkGenerator = new LinkGenerator(); string link = linkGenerator.GenerateLink(); using (Repository repo = new Repository()) { IScreen screenDAO = repo.AddScreen(link, base64Array); ScreenDTO screenDTO = new ScreenDTO() { Id = screenDAO.Id, Link = screenDAO.Link, Content = screenDAO.Content }; return(screenDTO); } }
public static ContentDTO ToDTO(this Content entity) { if (entity == null) { throw new ArgumentNullException("entity"); } var result = new ContentDTO() { ID = entity.ID, CreatedDate = entity.CreatedDate }; result.Type = entity.Type.GetDescription(); result.ContentBinary = entity.ContentBinary; result.MimeType = !string.IsNullOrEmpty(entity.MimeType) ? entity.MimeType : string.Empty; result.SeoFilename = !string.IsNullOrEmpty(entity.SeoFilename) ? entity.SeoFilename : string.Empty; result.ContentPath = !string.IsNullOrEmpty(entity.ContentPath) ? entity.ContentPath : string.Empty; result.AltAttribute = !string.IsNullOrEmpty(entity.AltAttribute) ? entity.AltAttribute : string.Empty; result.TitleAttribute = !string.IsNullOrEmpty(entity.TitleAttribute) ? entity.TitleAttribute : string.Empty; return result; }
private string generateControllerResult(decimal projectId, ContentDTO contentDTO, TemplateTypeDTO templateTypeDTO, decimal pageContentId) { string allFunctionList = ""; string allDirectiveList = ""; string result = BLL.BLTemplateType.getTypeByName("angularJs-Content").TokenizeString; WebDefinerDTO templateWebDefinerDTO = BLL.BLWebDefiner.getWebDefinerInfo(templateTypeDTO.WebDefinerId); List <WebDefinerDTO> webDefinerList = BLL.BLWebDefiner.getComponentListWebDefinerForPageContent(pageContentId); string allInjectorList = templateWebDefinerDTO.InjectorList; string allVariableList = templateWebDefinerDTO.VariableList; string allParamList = templateWebDefinerDTO.ParamList; foreach (WebDefinerDTO webDefinerDTO in webDefinerList) { allParamList += "," + webDefinerDTO.ParamList; allVariableList += "," + webDefinerDTO.VariableList; allFunctionList += "\n " + webDefinerDTO.FunctionList; allDirectiveList += "\n " + webDefinerDTO.Directive; allInjectorList += "," + webDefinerDTO.InjectorList; } //todo replace App with token result = result.Replace("<<<Page.AppName>>>", BLL.BLProject.getProjectToken(projectId, "Page.AppName")); result = result.Replace("<<<ControllerName>>>", "Ctrl" + contentDTO.PageContentId); result = result.Replace("<<<Variables>>>", Parser.clearExtraComa(allVariableList)); result = result.Replace("<<<Params>>>", Parser.clearExtraComa(allParamList)); result = result.Replace("<<<Functions>>>", "<<<Functions>>> \n" + allFunctionList); result = result.Replace("<<<DirectiveList>>>", allDirectiveList); result = result.Replace("<<<InjectorList>>>", Parser.clearExtraComa(allInjectorList)); string controllerClicks = getControllerClick(contentDTO); result = result.Replace("<<<Functions>>>", controllerClicks); result = Parser.removeUnUsableTokens(result); return(result); }
public PostDTO(WallPostData post, string[] tags) { Date = (DateTime)post.Date; //Dangerous! Author = post.Author; AuthorPicture = post.AuthorPicUrl; Text = post.Text; List <ContentDTO> contentsList = new List <ContentDTO>(); foreach (var attachment in post.Attachments) { ContentDTO contentDto = new ContentDTO() { Type = attachment.AttachmentType, Path = attachment.Uri }; contentsList.Add(contentDto); } Contents = contentsList; Hashtags = tags.ToList(); IsShared = false; OriginalPostId = -1; VkPostLink = post.Link; }
public string generatePageContent(string exportPath, decimal pageContentId) { contentDTO = BLL.BLPageContent.getContent(pageContentId); pageDTO = BLL.BLPageContent.getPage(pageContentId); layoutDTO = BLL.BLLayout.getLayoutInfo(contentDTO.ContentId, contentDTO.LayoutId); //templateTypeDTO = BLL.BLTemplateType.getProjectTemplateType(contentDTO.ProjectId); //global.js from templateType templateTypeDTO = BLL.BLTemplateType.getTypeByName("global.js"); projectDTO = BLL.BLProject.getProjectInfo(pageDTO.ProjectId); containerTypeDTO = BLL.BLContainerType.getContainerType(pageDTO.ContainerTypeId); //mainResult = getPageResult(); mainResult = templateTypeDTO.TokenizeString; mainResult = replacePageToken(mainResult, pageDTO.ProjectId, pageDTO.PageId); mainResult = replaceGolbalToken(mainResult, templateTypeDTO, pageDTO.ProjectId); //mainResult = replaceCurrentPage(pageDTO.PageId, pageContentId); //mainResult = replacePageControllers(mainResult, pageDTO.PageId); globalJsResult = replaceglobalJSToken(globalJsResult, pageDTO.ProjectId); globalJsResult = Parser.removeUnUsableTokens(globalJsResult); //mainResult = generateDesigns(mainResult, pageDTO.ProjectId, pageDTO.PageId); mainResult = Parser.removeUnUsableTokens(mainResult); mainResult = Parser.removeUnUsableAttributes(mainResult); contentResult = replaceLayouutComponent(pageContentId, contentDTO, layoutDTO); //contentResult += BLL.BLNavigation.getNavigationList(pageContentId); contentResult = Parser.removeUnUsableTokens(contentResult); contentResult = Parser.removeUnUsableAttributes(contentResult); contentResult = generateContentDesigns(projectDTO.ProjectId, pageDTO.PageId, contentResult, contentDTO); controllerResult = generateControllerResult(pageDTO.ProjectId, contentDTO, templateTypeDTO, pageContentId); BLL.BLDesign.savePageContentDesigns(exportPath, projectDTO, pageContentId); generateIndexResult(contentDTO.ProjectId); string path = exportPath + "/" + projectDTO.OwnerUserId + "/" + projectDTO.ProjectId; if (!Directory.Exists(exportPath)) { Directory.CreateDirectory(exportPath); } if (!Directory.Exists(path)) { BLL.BLProject.reCreateResources(exportPath, projectDTO); } saveFile(path, "index.html", indexResult); saveFile(path, "global.js", templateTypeglobalJs); if (!Directory.Exists(path + "/Content/" + pageDTO.Path)) { Directory.CreateDirectory(path + "/Content/" + pageDTO.Path); } if (!Directory.Exists(path + "/Content/" + contentDTO.Path)) { Directory.CreateDirectory(path + "/Content/" + contentDTO.Path); } saveFile(path, pageDTO.FullPath + ".html", getPageResult(pageDTO)); saveFile(path, contentDTO.FullPath + ".html", contentResult); saveFile(path, contentDTO.FullPath + ".js", controllerResult); saveFile(path, "main.html", mainResult); saveFile(path, "path.js", getPathJs(projectDTO)); saveFile(path, "dashboard.js", BLL.BLDashboard.getDashbordJsString(projectDTO.ProjectId)); saveFile(path, "part.js", BLL.BLDashboard.getPartJsString()); saveFile(path, "part.html", BLL.BLDashboard.getPartHTMLString()); saveFile(path, "/Table/table.js", BLL.BLTemplateType.getTypeByName("table.js").TokenizeString); saveDashboards(path, projectDTO.ProjectId); return(""); }
public decimal saveContentInfo(ContentDTO contentDTO) { return(contentEntity.saveContentInfo(contentDTO)); }
public IActionResult CreateContentOfProduct(ContentDTO contentDTO) { var apiJsonResponse = new ApiJsonResponse(); try { using (FoodInfoServiceContext context = new FoodInfoServiceContext()) { if (contentDTO != null) { if (contentDTO.Product.BarcodeId != null) { if (contentDTO.CreatedUserId != null) { using (var transaction = context.Database.BeginTransaction()) { if (context.Products.Any(x => x.BarcodeId == contentDTO.Product.BarcodeId && x.IsDeleted == false)) { contentDTO.Product.ID = context.Products.FirstOrDefault(x => x.BarcodeId == contentDTO.Product.BarcodeId && x.IsDeleted == false).ID; } else { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.BarcodIdRequired)); } if (context.Languages.Any(x => x.LanguageCode == contentDTO.Language.LanguageCode && x.IsDeleted == false)) { contentDTO.Language.ID = context.Languages.FirstOrDefault(x => x.LanguageCode == contentDTO.Language.LanguageCode && x.IsDeleted == false).ID; } else { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideLanguageCode)); } if (context.ProductContents.Any(x => x.Product.ID == contentDTO.Product.ID && x.IsDeleted == false && x.Language.ID == contentDTO.Language.ID)) { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ExistingContentForProduct)); } // contentDTO.NutritionFact.ID = context.NutritionFacts.FirstOrDefault(x => x.ID == contentDTO.NutritionFact.ID && x.IsDeleted == false).ID; var nutritionFacts = new NutritionFacts(); nutritionFacts = Mapper.Map <NutritionFacts>(contentDTO.NutritionFact); nutritionFacts.BarcodeId = contentDTO.Product.BarcodeId; nutritionFacts.CreatedUserId = contentDTO.CreatedUserId; nutritionFacts.LanguageCode = contentDTO.Language.LanguageCode; context.Add(nutritionFacts); context.SaveChanges(); contentDTO.NutritionFact.ID = context.NutritionFacts.Where(x => x.BarcodeId == contentDTO.Product.BarcodeId && x.LanguageCode == contentDTO.Language.LanguageCode && x.IsDeleted == false).FirstOrDefault().ID; var content = context.ProductContents.Add(Mapper.Map <ProductContent>(contentDTO)); context.SaveChanges(); transaction.Commit(); return(apiJsonResponse.ApiOkContentResult(Mapper.Map <ProductContent>(contentDTO))); } } else { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideACreatedUserId)); } } else { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.BarcodIdRequired)); } } else { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage)); } } } catch (Exception ex) { { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage)); } } }
public IActionResult GetProductContentByLanguageCode(LanguageAndProductDTO languageAndProductDTO) { var apiJsonResponse = new ApiJsonResponse(); try { using (FoodInfoServiceContext context = new FoodInfoServiceContext()) { if (languageAndProductDTO.LanguageCode != null) { if (context.Products.Any(x => x.BarcodeId == languageAndProductDTO.BarcodeId)) { if (context.ProductContents.Any(x => x.Language.LanguageCode == languageAndProductDTO.LanguageCode && x.IsDeleted == false && x.Product.BarcodeId == languageAndProductDTO.BarcodeId)) { var product = context.ProductContents.Where(x => x.Product.BarcodeId == languageAndProductDTO.BarcodeId && x.Language.LanguageCode == languageAndProductDTO.LanguageCode && x.IsDeleted == false) .Include(m => m.NutritionFact) .Include(m => m.Product).FirstOrDefault(); ContentDTO contentDTO = Mapper.Map <ContentDTO>(product); try { var comments = context.Comments.Where(x => x.ProductContent.ID == product.ID && x.IsDeleted == false).ToList(); if (comments != null) { List <CommentDTO> commentDTOs = new List <CommentDTO>(); // contentDTO.Comments = Mapper.Map<List<CommentDTO>>(comments); int i = 0; foreach (var item in comments) { var commentDTO = new CommentDTO(); var temp = context.User.Where(x => x.ID == item.CreatedUserId).FirstOrDefault(); commentDTO.CreatedDate = item.CreatedDate; commentDTO.CreatedUserId = item.CreatedUserId; commentDTO.Name = temp.Name; commentDTO.Surname = temp.Surname; commentDTO.Username = temp.Username; commentDTO.UserComment = item.UserComment; commentDTO.ProductContentId = item.ProductContent.ID; commentDTO.ModifiedDate = item.ModifiedDate; commentDTO.ModifiedUserId = item.ModifiedUserId; commentDTOs.Add(commentDTO); } contentDTO.Comments = commentDTOs; } } catch { } int totalVotes = context.Votes.Count(x => x.Product.BarcodeId == languageAndProductDTO.BarcodeId); if (totalVotes == 0) { contentDTO.AverageVote = 5.0M; } else { int count = 0; foreach (var item in context.Votes.Where(x => x.Product.BarcodeId == languageAndProductDTO.BarcodeId)) { if (item.UserVote != null) { count += (int)item.UserVote; } } if (count != 0) { contentDTO.AverageVote = decimal.Round((count / (decimal)totalVotes), 2); } else { contentDTO.AverageVote = 5.0M; } } return(apiJsonResponse.ApiOkContentResult(contentDTO)); } else { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.BarcodeIdOrLanguageCodeDoesNotFound)); } } else { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductDoesNotFound)); } } else { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideLanguageCode)); } } } catch (Exception ex) { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage)); } }
public ContentDTO paste(ContentDTO contentDTO, decimal pageId) { return(pageContentEntity.paste(contentDTO, pageId)); }
public ContentDTO SavePageContentInfo(ContentDTO contentDTO) { return(pageContentEntity.SavePageContentInfo(contentDTO)); }
public void SetPath(string exportPath, ContentDTO contentDTO) { BLL.BLPageContent.SavePageContentInfo(contentDTO); }
private string getControllerClick(ContentDTO contentDTO) { return(BLL.BLDesign.getControllerClick(contentDTO)); }