/// <summary> /// 将指定的商品归类到指定的商品分类中。 /// </summary> /// <param name="product">需要归类的商品。</param> /// <param name="category">商品分类。</param> /// <returns>用以表述商品及其分类之间关系的实体。</returns> public Categorization Categorize(Product product, Category category) { if (product == null) { throw new ArgumentNullException("product"); } if (category == null) { throw new ArgumentNullException("category"); } var categorization = categorizationRepository.Find(Specification <Categorization> .Eval(c => c.ProductID == product.ID)); if (categorization == null) { categorization = Categorization.CreateCategorization(product, category); categorizationRepository.Add(categorization); } else { categorization.CategoryID = category.ID; categorizationRepository.Update(categorization); } repositoryContext.Commit(); return(categorization); }
public async Task <ServiceResponse <bool> > Add(CategorizationDto categorizationDto) { ServiceResponse <bool> serviceResponse = new ServiceResponse <bool>(); try { Product product = await _context.Product.FirstOrDefaultAsync(p => p.Id == categorizationDto.ProductId); Category category = await _context.Category.FirstOrDefaultAsync(c => c.Id == categorizationDto.CategoryId); Categorization categorization = new Categorization { Product = product, Category = category }; await _context.Categorization.AddAsync(categorization); await _context.SaveChangesAsync(); serviceResponse.Data = true; } catch (Exception e) { serviceResponse.Data = false; serviceResponse.Success = false; serviceResponse.Message = e.Message; } return(serviceResponse); }
private void RebuildCategorisation_Callback() { CategoryEntry root = new CategoryEntry(null, "Add Menu", new CategoryEntry[] { Categorization.Items, Categorization.Mobiles }); Categorization.Export(root, "Data/objects.xml", "Objects"); MessageBox.Show(Core.MainForm, "Categorisation updated successfully", "Success"); }
private void AddSampleData() { var user1 = new User() { Email = "*****@*****.**", FirebaseUserId = "FIREBASE_ID_1" }; var user2 = new User() { Email = "*****@*****.**", FirebaseUserId = "FIREBASE_ID_2" }; var user3 = new User() { Email = "*****@*****.**", FirebaseUserId = "FIREBASE_ID_3" }; _context.Add(user1); _context.Add(user2); _context.Add(user3); _context.SaveChanges(); var categorization1 = new Categorization() { Type = "Alphabetical" }; var categorization2 = new Categorization() { Type = "Part of Speech" }; _context.Add(categorization1); _context.Add(categorization2); _context.SaveChanges(); var collection1 = new Collection() { UserId = 1, CategorizationId = 1, Name = "Monsters", Description = "Monsters and related words It becomes.", Pinned = false, CreationDate = DateTime.Now - TimeSpan.FromDays(15) }; var collection2 = new Collection() { UserId = 1, CategorizationId = 1, Name = "Scary places", Description = "Spooky places It probably hangs at.", Pinned = false, CreationDate = DateTime.Now - TimeSpan.FromDays(10) }; var collection3 = new Collection() { UserId = 2, CategorizationId = 1, Name = "Fear", Description = "All the words that cause scary feelings.", Pinned = false, CreationDate = DateTime.Now - TimeSpan.FromDays(10) }; var collection4 = new Collection() { UserId = 3, CategorizationId = 2, Name = "Research", Description = "Things related to researching", Pinned = false, CreationDate = DateTime.Now - TimeSpan.FromDays(5) }; _context.Add(collection1); _context.Add(collection2); _context.Add(collection3); _context.Add(collection4); _context.SaveChanges(); var project1 = new Project() { UserId = 1, Name = "The Haunted House", CreationDate = DateTime.Now - TimeSpan.FromDays(15) }; var project2 = new Project() { UserId = 1, Name = "Spooky Stories", CreationDate = DateTime.Now - TimeSpan.FromDays(10) }; var project3 = new Project() { UserId = 2, Name = "Under the Bed", CreationDate = DateTime.Now - TimeSpan.FromDays(10) }; var project4 = new Project() { UserId = 3, Name = "Big Untitled Story", CreationDate = DateTime.Now - TimeSpan.FromDays(5) }; _context.Add(project1); _context.Add(project2); _context.Add(project3); _context.Add(project4); _context.SaveChanges(); }
private void AddSampleData() { var user1 = new User() { Email = "*****@*****.**", FirebaseUserId = "FIREBASE_ID_1" }; var user2 = new User() { Email = "*****@*****.**", FirebaseUserId = "FIREBASE_ID_2" }; var user3 = new User() { Email = "*****@*****.**", FirebaseUserId = "FIREBASE_ID_3" }; _context.Add(user1); _context.Add(user2); _context.Add(user3); _context.SaveChanges(); var categorization1 = new Categorization() { Type = "Alphabetical" }; var categorization2 = new Categorization() { Type = "Part of Speech" }; _context.Add(categorization1); _context.Add(categorization2); _context.SaveChanges(); var collection1 = new Collection() { UserId = 1, CategorizationId = 1, Name = "Monsters", Description = "Monsters and related words It becomes.", Pinned = false, CreationDate = DateTime.Now - TimeSpan.FromDays(15) }; var collection2 = new Collection() { UserId = 1, CategorizationId = 1, Name = "Scary places", Description = "Spooky places It probably hangs at.", Pinned = false, CreationDate = DateTime.Now - TimeSpan.FromDays(10) }; var collection3 = new Collection() { UserId = 2, CategorizationId = 1, Name = "Fear", Description = "All the words that cause scary feelings.", Pinned = false, CreationDate = DateTime.Now - TimeSpan.FromDays(10) }; var collection4 = new Collection() { UserId = 2, CategorizationId = 1, Name = "Basements", Description = "Nobody likes them.", Pinned = false, CreationDate = DateTime.Now - TimeSpan.FromDays(10) }; _context.Add(collection1); _context.Add(collection2); _context.Add(collection3); _context.Add(collection4); _context.SaveChanges(); var word1 = new Word() { UserId = 1, CollectionId = 1, MwWordId = "12345", Name = "Scares", LastViewed = DateTime.Now - TimeSpan.FromDays(15) }; var word2 = new Word() { UserId = 1, CollectionId = 1, MwWordId = "12345", Name = "Zombie", LastViewed = DateTime.Now - TimeSpan.FromDays(15) }; var word3 = new Word() { UserId = 1, CollectionId = 1, MwWordId = "12345", Name = "Werewolf", LastViewed = DateTime.Now - TimeSpan.FromDays(15) }; var word4 = new Word() { UserId = 1, CollectionId = 2, MwWordId = "12345", Name = "Vampire", LastViewed = DateTime.Now - TimeSpan.FromDays(15) }; _context.Add(word1); _context.Add(word2); _context.Add(word3); _context.Add(word4); _context.SaveChanges(); }