コード例 #1
0
        public void CreateItem(int buyOut, int userId, int expire, string[] tags, string title, string description, string[] images)
        {
            List <ImageEntity> newImages = new List <ImageEntity>();

            for (int i = 0; i < images.Length; i++)
            {
                ImageEntity item = new ImageEntity();
                item.ImageOfItem = images[i];
                newImages[i]     = item;
            }
            List <TagEntity> newTags = new List <TagEntity>();

            for (int i = 0; i < tags.Length; i++)
            {
                TagEntity tag = new TagEntity();
                tag.Type   = tags[i];
                newTags[i] = tag;
            }
            ItemEntity itemEntity = new ItemEntity()
            {
                BuyOutPrice       = buyOut,
                DateCreated       = DateTime.Now,
                ExpirationDate    = DateTime.Now.AddDays(expire),
                Title             = title,
                Images            = newImages,
                Tags              = newTags,
                DescriptionOfItem = description,
                UserIdSeller      = userId,
            };

            GenerateTags(itemEntity.Title, itemEntity.ItemId);
            db.Add(itemEntity);
            db.SaveChanges();
        }
コード例 #2
0
 public static void Initialize(IServiceProvider serviceProvider)
 {
     using (var context = new VareDataModelContext())
     {
         context.Database.EnsureCreated();
         //Dummiedata.
         if (context.Items.Any())
         {
             return;   // DB has been seeded
         }
         DummyData dd = new DummyData();
         dd.InsertDummyData(context);
         context.SaveChanges();
     }
 }