public HomeController(EaDbContext dbContext, UserManager <EaUser> userManager, SignInManager <EaUser> signInManager, ContentRepository contentRepository, ContentFileRepository contentFileRepository) { _dbContext = dbContext; _userManager = userManager; _contentRepository = contentRepository; _contentFileRepository = contentFileRepository; _signInManager = signInManager; }
public ActionResult SetMainImage(int fileId, int id, String entityType) { if (entityType.Equals(StoreConstants.ProductType, StringComparison.InvariantCultureIgnoreCase)) { ProductFileRepository.SetMainImage(id, fileId); } else if (entityType.Equals(StoreConstants.BlogsType, StringComparison.InvariantCultureIgnoreCase) || entityType.Equals(StoreConstants.NewsType, StringComparison.InvariantCultureIgnoreCase)) { ContentFileRepository.SetMainImage(id, fileId); } return(Json(new { fileId, id }, JsonRequestBehavior.AllowGet)); }
public ContentController(EaDbContext dbContext, UserManager <EaUser> userManager, ContentRepository contentRepository, SignInManager <EaUser> signInManager, GroupRepository groupRepository, LikeRepository likeRepository, CommentRepository commentRepository, ContentFileRepository contentFileRepository) { _userManager = userManager; _contentRepository = contentRepository; _signInManager = signInManager; _likeRepository = likeRepository; _commentRepository = commentRepository; _contentFileRepository = contentFileRepository; _groupRepository = groupRepository; _dbContext = dbContext; }
public ActionResult GetImagesByLabels(int storeId, String[] labels, String entityType, int id) { var images = FileManagerRepository.GetFilesByStoreIdAndLabels(storeId, labels); var list = new List <FileManager>(); if (entityType.Equals(StoreConstants.ProductType, StringComparison.InvariantCultureIgnoreCase)) { var productFiles = ProductFileRepository.GetProductFilesByProductId(id); list.AddRange(images.Where(r => !productFiles.Select(r1 => r1.FileManagerId).Contains(r.Id))); } else if (entityType.Equals(StoreConstants.BlogsType, StringComparison.InvariantCultureIgnoreCase) || entityType.Equals(StoreConstants.NewsType, StringComparison.InvariantCultureIgnoreCase)) { var contentFiles = ContentFileRepository.GetContentFilesByContentId(id); list.AddRange(images.Where(r => !contentFiles.Select(r1 => r1.FileManagerId).Contains(r.Id))); } return(Json(list, JsonRequestBehavior.AllowGet)); }
public ActionResult SaveOrEdit(Content content, int[] selectedFileId = null, int[] selectedLabelId = null) { try { if (ModelState.IsValid) { if (content.CategoryId == 0) { var labels = new List <LabelLine>(); var fileManagers = new List <FileManager>(); int mainImageFileManagerId = 0; if (content.Id > 0) { content = ContentRepository.GetContentWithFiles(content.Id); labels = LabelLineRepository.GetLabelLinesByItem(content.Id, ContentType); fileManagers = content.ContentFiles.Select(r => r.FileManager).ToList(); var mainImage = content.ContentFiles.FirstOrDefault(r => r.IsMainImage); if (mainImage != null) { mainImageFileManagerId = mainImage.FileManagerId; } } ViewBag.MainImageId = mainImageFileManagerId; ViewBag.SelectedLabels = labels.Select(r => r.LabelId).ToArray(); ViewBag.FileManagers = fileManagers; ModelState.AddModelError("CategoryId", "You should select category from category tree."); return(View(content)); } if (content.Id == 0) { ContentRepository.Add(content); ClearCache(content.StoreId); } else { ContentRepository.Edit(content); } ContentRepository.Save(); int contentId = content.Id; if (selectedFileId != null) { ContentFileRepository.SaveContentFiles(selectedFileId, contentId); } LabelLineRepository.SaveLabelLines(selectedLabelId, contentId, ContentType); if (IsSuperAdmin) { return(RedirectToAction("Index", new { storeId = content.StoreId, categoryId = content.CategoryId })); } else { return(RedirectToAction("Index", new { categoryId = content.CategoryId })); } } } catch (Exception ex) { Logger.Error(ex, "Unable to save changes:" + ex.StackTrace, content); //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(content)); }
public ActionResult GetFiles(int contentId) { var files = ContentFileRepository.GetContentFilesByContentId(contentId); return(Json(files, JsonRequestBehavior.AllowGet)); }