public async Task AddLabel() { LabelDto addedLabel = await _labelRepository.Add(new CreateLabelDto { Description = "buy phone", CreatedBy = 1 }); Assert.IsNotNull(addedLabel); Assert.AreEqual("buy phone", addedLabel.Description); }
private SVP.CIL.Domain.Label LabelCreate(AppDbContext dbc, SVP.CIL.Domain.Label target) { var label = Mapper.Map <Label>(target); var repo = new LabelRepository(dbc); repo.Add(label); 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 int Add(Label model) { if (ContextUser.IsLogined) { model.CreateUser = ContextUser.Email; } var time = DateTime.Now; model.CreateTime = time; model.UpdateTime = time; model.Enable = 1; var id = _labelRepository.Add(model); return(id); }
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); } }
/// <summary> /// InMemoryデータベース用のユニットテストデータを作成する /// </summary> void ImportInitializeData(int threadId, SimpleInjector.Container container) { var @dbc = (AppDbContext)container.GetInstance <IAppDbContext>(); // Category var repo_Category = new CategoryRepository(@dbc); repo_Category.Add(new Category { Id = 2, Name = "テストカテゴリA" }); repo_Category.Add(new Category { Id = 3, Name = "テストカテゴリA2" }); repo_Category.Add(new Category { Id = 4, Name = "テストカテゴリA3" }); // Label var repo_Label = new LabelRepository(@dbc); repo_Label.Add(new Label { Id = 1, Name = "テストラベル" }); repo_Label.Add(new Label { Id = 2, Name = "テストラベル_2", Category = (Category)repo_Category.Load(1) }); // Content var repo_Content = new ContentRepository(@dbc); repo_Content.Add(new Content { Id = 1, Name = "Content1", IdentifyKey = "IDEN_Content1" }); repo_Content.Add(new Content { Id = 2, Name = "Content2", IdentifyKey = "IDEN_Content2", }); repo_Content.Add(new Content { Id = 3, Name = "Content3", IdentifyKey = "IDEN_Content3" }); // Workspace var repo_Workspace = new WorkspaceRepository(@dbc); var workspace1 = new Workspace { Id = 1, Name = "UT_Workspace", PhysicalPath = Path.Combine(TESTDATADIRECTORY, "PixstockSrvUT_" + threadId) }; repo_Workspace.Add(workspace1); // FileMappingInfo var repo_FileMappingInfo = new FileMappingInfoRepository(@dbc); repo_FileMappingInfo.Add(new FileMappingInfo { Id = 1, AclHash = "ABC1", Workspace = workspace1 }); @dbc.SaveChanges(); var label2 = repo_Label.Load(2L); label2.Contents.Add(new Label2Content { ContentId = 1L, Content = (Content)repo_Content.Load(1L), LabelId = 2L, Label = label2 }); @dbc.SaveChanges(); }