public async Task <bool> Create(ProductServiceModel productServiceModel) { //works var productType = this.context.ProductTypes.FirstOrDefault(p => p.Name == productServiceModel.ProductType.Name); var product = productServiceModel.To <Product>(); product.ProductType = productType; // THIS IS FOR PREVENTING THE NEW CREATION OF PRODUCT TYPE! #region old mapping // new Product //{ // Name = productServiceModel.Name, // Price = productServiceModel.Price, // ManufacturedOn = productServiceModel.ManufacturedOn, // ProductType=productType, // Picture=productServiceModel.Picture //}; #endregion context.Products.Add(product); int result = await context.SaveChangesAsync(); return(result > 0); }
public async Task <bool> Create(ProductServiceModel model) { ProductType productTypeDb = context.ProductTypes .SingleOrDefault(productType => productType.Name == model.ProductType.Name); Product product = Mapper.Map <Product>(model); product.ProductType = productTypeDb; context.Products.Add(product); int result = await context.SaveChangesAsync(); return(result > 0); }
public async Task <bool> Create(ProductServiceModel productServiceModel) { Product product = new Product { Name = productServiceModel.Name, Price = productServiceModel.Price, ManufacturedOn = productServiceModel.ManufacturedOn }; context.Products.Add(product); int result = await context.SaveChangesAsync(); return(result > 0); }
public async Task <bool> Create(ProductServiceModel productServiceModel) { ProductType productTypeFromDb = GetProductTypeByName(productServiceModel.ProductType.Name); if (productTypeFromDb == null) { throw new ArgumentNullException(nameof(productTypeFromDb)); } Product product = mapper.Map <Product>(productServiceModel); product.ProductType = productTypeFromDb; context.Products.Add(product); int result = await context.SaveChangesAsync(); return(result > 0); }
public async Task <bool> Create(ProductServiceModel inputModel) { var productType = await this.context.ProductTypes.SingleOrDefaultAsync(pt => pt.Name == inputModel.ProdudctType.Name); Product product = new Product { Name = inputModel.Name, Price = inputModel.Price, ManufacturedOn = inputModel.ManufacturedOn, Picture = inputModel.Picture, ProdudctType = productType, ProdudctTypeId = productType.Id }; await context.Products.AddAsync(product); int result = await context.SaveChangesAsync(); return(result > 0); }
private async void SeedData(StopifyDbContext context) { context.AddRange(GetDummyData()); await context.SaveChangesAsync(); }