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 <IActionResult> Details(long Id) { ProductServiceModel productFromDB = this.productService.GetById(Id); ProductCreateInputModel product = productFromDB.To <ProductCreateInputModel>(); var FrequencyList = product.FrequencyRule = productFromDB.FrequencyRule.Split(",").ToList(); product.FrequencyRule = FrequencyList; return(this.View(product)); }
public async Task <ProductServiceModel> CreateAsync(ProductServiceModel productServiceModel) { Product product = productServiceModel.To <Product>(); await this.context.Products.AddAsync(product); await this.context.SaveChangesAsync(); return(product.To <ProductServiceModel>()); }