public ActionResult DeleteConfirmed(int id) { Label label = LabelRepository.GetSingle(id); try { LabelRepository.Delete(label); LabelRepository.Save(); if (IsSuperAdmin) { return(RedirectToAction("Index", new { storeId = label.StoreId })); } else { return(RedirectToAction("Index")); } } catch (Exception ex) { Logger.Error(ex, "Unable to delete it:" + ex.StackTrace, label); ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(label)); }
public void Test_RelationUpdate_01() { _logger.Trace(">>> Labelモデルの読み込みテストを開始"); using (InitializeFact()) { { var @dbc = (AppDbContext)container.GetInstance <IAppDbContext>(); var repo = new LabelRepository(dbc); var repoc = new ContentRepository(dbc); var entity = repo.Load(2L); var content = repoc.Load(2L); entity.Contents.Add(new Model.Label2Content { Content = (Content)content, Label = entity }); repo.Save(); } { var @dbc = (AppDbContext)container.GetInstance <IAppDbContext>(); var repo = new LabelRepository(dbc); var entity = repo.Load(2L); Assert.Equal(entity.Contents[1].Content.Id, 2L); } } }
private SVP.CIL.Domain.Label LabelUpdate(AppDbContext dbc, SVP.CIL.Domain.Label target) { var repo = new LabelRepository(dbc); var label = repo.Load(target.Id); Mapper.Map <SVP.CIL.Domain.Label, Label>(target, label); repo.Save(); dbc.SaveChanges(); var domainLabel = Mapper.Map <SVP.CIL.Domain.Label>(label); return(domainLabel); }
public ActionResult CreatingNewLabel(String labelName) { Label label = new Label(); label.Name = labelName; label.ParentId = 1; LabelRepository.Add(label); int labelId = LabelRepository.Save(); label = LabelRepository.GetSingle(labelId); return(Json(label, JsonRequestBehavior.AllowGet)); }
public void Test_Update_01() { _logger.Trace(">>> Labelモデルの読み込みテストを開始"); using (InitializeFact()) { string updateName = "POTEST"; { var @dbc = (AppDbContext)container.GetInstance <IAppDbContext>(); var repo = new LabelRepository(dbc); var entity = repo.Load(2L); entity.Name = updateName; repo.Save(); } { var @dbc = (AppDbContext)container.GetInstance <IAppDbContext>(); var repo = new LabelRepository(dbc); var entity = repo.Load(2L); Assert.Equal(entity.Name, updateName); } } }
public ActionResult SaveOrEdit(Label label) { try { if (ModelState.IsValid) { if (label.Id == 0) { LabelRepository.Add(label); } else { LabelRepository.Edit(label); } LabelRepository.Save(); if (IsSuperAdmin) { return(RedirectToAction("Index", new { storeId = label.StoreId })); } else { return(RedirectToAction("Index")); } } } catch (Exception ex) { Logger.Error(ex, "Unable to save:" + ex.StackTrace, label); //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(label)); }
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); }
private void CopyStoreData(int copyStoreId, int newStoreId) { StoreDbContext.Configuration.ProxyCreationEnabled = false; try { var items = NavigationRepository.GetNavigationsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; NavigationRepository.Add(s); } NavigationRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = LocationRepository.GetLocationsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; LocationRepository.Add(s); } LocationRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = EmailListRepository.GetStoreEmailList(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; EmailListRepository.Add(s); } EmailListRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = BrandRepository.GetBrandsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; BrandRepository.Add(s); } BrandRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = ContactRepository.GetContactsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; ContactRepository.Add(s); } ContactRepository.Save(); } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } int productCategoryId = 0; try { var items = ProductCategoryRepository.GetProductCategoriesByStoreId(copyStoreId); foreach (var productCategory in items) { var s = GeneralHelper.DataContractSerialization(productCategory); s.Id = 0; s.StoreId = newStoreId; ProductCategoryRepository.Add(s); ProductCategoryRepository.Save(); productCategoryId = s.Id; } } catch (Exception ex) { Logger.Error(ex, "ProductCategoryRepository:CopyStore"); } int blogCategoryId = 0; int newsCategoryId = 0; try { var items = CategoryRepository.GetCategoriesByStoreId(copyStoreId, StoreConstants.BlogsType); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; CategoryRepository.Add(s); CategoryRepository.Save(); blogCategoryId = s.Id; } items = CategoryRepository.GetCategoriesByStoreId(copyStoreId, StoreConstants.NewsType); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; CategoryRepository.Add(s); CategoryRepository.Save(); newsCategoryId = s.Id; } } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = ProductRepository.GetProductsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.ProductCategoryId = productCategoryId; s.StoreId = newStoreId; ProductRepository.Add(s); ProductRepository.Save(); } } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = ContentRepository.GetContentsByStoreId(copyStoreId, "", StoreConstants.BlogsType); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; s.CategoryId = blogCategoryId; ContentRepository.Add(s); ContentRepository.Save(); } items = ContentRepository.GetContentsByStoreId(copyStoreId, "", StoreConstants.NewsType); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; s.CategoryId = newsCategoryId; ContentRepository.Add(s); ContentRepository.Save(); } } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = LabelRepository.GetLabelsByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; LabelRepository.Add(s); LabelRepository.Save(); } } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } try { var items = ActivityRepository.GetActivitiesByStoreId(copyStoreId, ""); foreach (var item in items) { var s = GeneralHelper.DataContractSerialization(item); s.Id = 0; s.StoreId = newStoreId; ActivityRepository.Add(s); ActivityRepository.Save(); } } catch (Exception ex) { Logger.Error(ex, "CopyStore", newStoreId); } }