public ActionResult DeleteConfirmed(int id) { Content content = ContentRepository.GetSingle(id); try { LabelLineRepository.DeleteLabelLinesByItem(id, ContentType); ContentRepository.Delete(content); ContentRepository.Save(); ClearCache(content.StoreId); 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 delete it:" + ex.StackTrace, content); ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(content)); }
// // GET: /Content/Create public ActionResult SaveOrEdit(int id = 0, int selectedStoreId = 0, int selectedCategoryId = 0) { var content = new Content(); content.CategoryId = selectedCategoryId; content.StoreId = GetStoreId(selectedStoreId); var labels = new List <LabelLine>(); var fileManagers = new List <FileManager>(); int mainImageFileManagerId = 0; if (id == 0) { content.Type = ContentType; content.UpdatedDate = DateTime.Now; content.CreatedDate = DateTime.Now; content.State = true; } else { content = ContentRepository.GetContentWithFiles(id); content.UpdatedDate = DateTime.Now; labels = LabelLineRepository.GetLabelLinesByItem(id, ContentType); fileManagers = content.ContentFiles.Select(r => r.FileManager).ToList(); if (!CheckRequest(content)) //security for right store and its item. { return(HttpNotFound("Not Found")); } var mainImage = content.ContentFiles.FirstOrDefault(r => r.IsMainImage); if (mainImage != null) { mainImageFileManagerId = mainImage.FileManagerId; } } ViewBag.SelectedLabels = labels.Select(r => r.LabelId).ToArray(); ViewBag.FileManagers = fileManagers; ViewBag.MainImageId = mainImageFileManagerId; return(View(content)); }
// // GET: /Product/Create public ActionResult SaveOrEdit(int id = 0, int selectedStoreId = 0, int selectedCategoryId = 0) { var content = new Product(); content.ProductCategoryId = selectedCategoryId; content.StoreId = GetStoreId(selectedStoreId); var labels = new List <LabelLine>(); var fileManagers = new List <FileManager>(); int mainImageFileManagerId = 0; if (id == 0) { content.Type = StoreConstants.ProductType; content.CreatedDate = DateTime.Now; content.State = true; content.UpdatedDate = DateTime.Now; } else { content = ProductRepository.GetSingleIncluding(id, r => r.ProductFiles.Select(r1 => r1.FileManager)); if (!CheckRequest(content)) //security for right store and its item. { return(HttpNotFound("Not Found")); } content.UpdatedDate = DateTime.Now; labels = LabelLineRepository.GetLabelLinesByItem(id, StoreConstants.ProductType); fileManagers = content.ProductFiles.Select(r => r.FileManager).ToList(); var mainImage = content.ProductFiles.FirstOrDefault(r => r.IsMainImage); if (mainImage != null) { mainImageFileManagerId = mainImage.FileManagerId; } } ViewBag.LabelLines = labels; ViewBag.FileManagers = fileManagers; ViewBag.MainImageId = mainImageFileManagerId; return(View(content)); }
public ActionResult DeleteConfirmed(int id) { Product product = ProductRepository.GetSingle(id); if (product == null) { return(HttpNotFound()); } try { if (!CheckRequest(product)) { return(new HttpNotFoundResult("Not Found")); } ProductRepository.Delete(product); ProductRepository.Save(); ClearCache(product.StoreId); LabelLineRepository.DeleteLabelLinesByItem(product.Id, StoreConstants.ProductType); ProductFileRepository.DeleteProductFileByProductId(product.Id); if (IsSuperAdmin) { return(RedirectToAction("Index", new { storeId = product.StoreId, categoryId = product.ProductCategoryId })); } else { return(RedirectToAction("Index", new { categoryId = product.ProductCategoryId })); } } catch (Exception ex) { Logger.Error(ex, "Unable to delete product:" + ex.StackTrace, product); ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(product)); }
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 SaveOrEdit(Product product, int[] selectedFileId = null, int[] selectedLabelId = null) { try { if (ModelState.IsValid) { if (!CheckRequest(product)) { return(new HttpNotFoundResult("Not Found")); } if (product.ProductCategoryId == 0) { int mainImageFileManagerId = 0; List <FileManager> fileManagers = new List <FileManager>(); var labelList = new List <LabelLine>(); if (product.Id > 0) { var content = ProductRepository.GetSingleIncluding(product.Id, r => r.ProductFiles.Select(r1 => r1.FileManager)); fileManagers = content.ProductFiles.Select(r => r.FileManager).ToList(); labelList = LabelLineRepository.GetLabelLinesByItem(product.Id, StoreConstants.ProductType); var mainImage = content.ProductFiles.FirstOrDefault(r => r.IsMainImage); if (mainImage != null) { mainImageFileManagerId = mainImage.FileManagerId; } } ViewBag.FileManagers = fileManagers; ViewBag.LabelLines = labelList; ViewBag.MainImageId = mainImageFileManagerId; ModelState.AddModelError("ProductCategoryId", "You should select category from category tree."); return(View(product)); } product.Description = GetCleanHtml(product.Description); if (product.Id == 0) { ProductRepository.Add(product); ClearCache(product.StoreId); } else { ProductRepository.Edit(product); } ProductRepository.Save(); int contentId = product.Id; if (selectedFileId != null) { ProductFileRepository.SaveProductFiles(selectedFileId, contentId); } LabelLineRepository.SaveLabelLines(selectedLabelId, contentId, StoreConstants.ProductType); if (IsSuperAdmin) { return(RedirectToAction("Index", new { storeId = product.StoreId, categoryId = product.ProductCategoryId })); } else { return(RedirectToAction("Index", new { categoryId = product.ProductCategoryId })); } } } catch (Exception ex) { Logger.Error(ex, "Unable to save changes:" + ex.StackTrace, product); //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(product)); }
protected bool SaveImagesLabels(string[] labels, List <string> selectedFiles, int storeId) { Boolean isNewLabelExists = false; try { foreach (var label in labels) { if (label.ToInt() > 0) { foreach (var m in selectedFiles) { LabelLine labelLine = new LabelLine(); labelLine.ItemId = m.ToInt(); labelLine.ItemType = StoreConstants.Files; labelLine.LabelId = label.ToInt(); LabelLineRepository.Add(labelLine); } } else { var existingLabel = LabelRepository.GetLabelByName(label, storeId); int labelId = 0; if (existingLabel == null) { if (!String.IsNullOrEmpty(label)) { var newLabel = new Label(); newLabel.StoreId = storeId; newLabel.Name = label; newLabel.ParentId = 1; newLabel.State = true; newLabel.Ordering = 1; newLabel.CreatedDate = DateTime.Now; newLabel.UpdatedDate = DateTime.Now; LabelRepository.Add(newLabel); LabelRepository.Save(); labelId = newLabel.Id; } } else { labelId = existingLabel.Id; } if (labelId > 0) { isNewLabelExists = true; foreach (var m in selectedFiles) { var labelLine = new LabelLine(); labelLine.ItemId = m.ToInt(); labelLine.ItemType = StoreConstants.Files; labelLine.LabelId = labelId; LabelLineRepository.Add(labelLine); } } } } try { LabelLineRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "Error is " + ex.StackTrace, storeId, labels); } } catch (Exception ex) { Logger.Error(ex, "Unable to save labels:" + ex.StackTrace); } return(isNewLabelExists); }