Beispiel #1
0
 //MAPPING PRODUCT
 //Entity-->data object
 public static Library.Product MapEFWithProduct(Entities.Product EProduct)
 {
     return(new Library.Product
     {
         PID = EProduct.Pid,
         Names = EProduct.Names,
         Model = EProduct.Model,
         Price = EProduct.Price
     });
 }
 public static ProductModel MapToModel(this Entity.Product entity)
 {
     return(new ProductModel
     {
         CreatedDate = entity.CreatedDate,
         Id = entity.Id,
         Name = entity.Name,
         Price = entity.Price,
         Sku = entity.Sku
     });
 }
        private void SampleData()
        {
            var lastItem = _dbContext.Products.LastOrDefault();
            int count    = 1;

            if (lastItem != null)
            {
                count = lastItem.Id + 1;
            }

            for (int i = count; i < (count + 10); i++)
            {
                var p = new DataAccess.Entities.Product
                {
                    CreatedDate = DateTime.Now,
                    Name        = $"Product {i}",
                    Price       = new Random().Next(20000, 100000),
                    Sku         = $"Sku {i}"
                };
                _dbContext.Products.Add(p);
            }

            _dbContext.SaveChanges();
        }