public ActionResult ImportExcel(int id, HttpPostedFileBase excelFile = null) { if (excelFile == null) { return(RedirectToAction("Index", new { storePageDesignId = id })); } var dt = ExcelHelper.PostValues(excelFile); int selectedStoreId = id; var resultList = PageDesignRepository.GetPageDesignByStoreId(selectedStoreId, ""); var pageDesingsExcelReport = MapToListHelper.ToList <PageDesign>(dt); foreach (var pageDesign in pageDesingsExcelReport.Where(r => !r.Name.Equals("Name", StringComparison.InvariantCultureIgnoreCase) && !r.PageTemplate.Equals("PageTemplate", StringComparison.InvariantCultureIgnoreCase))) { pageDesign.StorePageDesignId = id; var pageDesignTask = resultList.FirstOrDefault(r => r.Name.Equals(pageDesign.Name, StringComparison.InvariantCultureIgnoreCase)); if (pageDesignTask == null) { pageDesign.Id = 0; PageDesignRepository.Add(pageDesign); } else { pageDesignTask.PageTemplate = pageDesign.PageTemplate; PageDesignRepository.Edit(pageDesignTask); } pageDesign.CreatedDate = DateTime.Now; pageDesign.UpdatedDate = DateTime.Now; } PageDesignRepository.Save(); return(RedirectToAction("Index", new { storePageDesignId = id })); }
public ActionResult SaveOrEdit(PageDesign pagedesign) { var spd = StorePageDesignRepository.GetSingle(pagedesign.StorePageDesignId); ViewBag.StorePageDesignName = spd.Name; try { if (ModelState.IsValid) { if (pagedesign.Id > 0) { PageDesignRepository.Edit(pagedesign); } else { var isSamePageNameExists = PageDesignRepository.GetPageDesignByStoreId(pagedesign.StorePageDesignId, "") .Any(r => r.Name.Equals(pagedesign.Name, StringComparison.InvariantCultureIgnoreCase)); if (isSamePageNameExists) { ModelState.AddModelError("", "Same Page Desing Name exists, put a different name."); return(View(pagedesign)); } PageDesignRepository.Add(pagedesign); } PageDesignRepository.Save(); if (IsSuperAdmin) { return(RedirectToAction("SaveOrEdit", new { id = pagedesign.Id, storePageDesignId = pagedesign.StorePageDesignId })); } else { return(RedirectToAction("Index")); } } } catch (Exception ex) { Logger.Error(ex, "Unable to save:" + ex.StackTrace, pagedesign); //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(pagedesign)); }
public ActionResult SetPageDesignText(int id = 0, String text = "", String name = "", int storePageDesignId = 0) { var item = new PageDesign(); if (id == 0) { if (storePageDesignId != 0 && !String.IsNullOrEmpty(name)) { var isSamePageNameExists = PageDesignRepository.GetPageDesignByStoreId(storePageDesignId, "") .Any(r => r.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); if (isSamePageNameExists) { return(Json("Same name exists.", JsonRequestBehavior.AllowGet)); } item.PageTemplate = text; item.CreatedDate = DateTime.Now; item.State = true; item.Name = name; item.Type = name; item.UpdatedDate = DateTime.Now; PageDesignRepository.Add(item); } } else { item = PageDesignRepository.GetSingle(id); item.PageTemplate = text; item.Name = name; item.Type = name; item.UpdatedDate = DateTime.Now; PageDesignRepository.Edit(item); } PageDesignRepository.Save(); return(Json("", JsonRequestBehavior.AllowGet)); }
public ActionResult CopyPageDesign(int id) { PageDesign pagedesign = PageDesignRepository.GetSingle(id); try { var guid = Guid.NewGuid().ToString(); var pagedesignCopy = new PageDesign(); pagedesignCopy.PageTemplate = pagedesign.PageTemplate; pagedesignCopy.Name = pagedesign.Name + "_" + guid; pagedesignCopy.Type = pagedesign.Type + "_" + guid; pagedesignCopy.Id = 0; pagedesignCopy.CreatedDate = DateTime.Now; pagedesignCopy.State = true; pagedesignCopy.UpdatedDate = DateTime.Now; pagedesignCopy.StorePageDesignId = pagedesign.StorePageDesignId; PageDesignRepository.Add(pagedesignCopy); PageDesignRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "Unable to save:" + ex.StackTrace, pagedesign); //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."); } if (IsSuperAdmin) { return(RedirectToAction("Index", new { storePageDesignId = pagedesign.StorePageDesignId })); } else { return(RedirectToAction("Index")); } }