public ActionResult Create(ProductCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateProductService(); if (service.CreateProduct(model)) { TempData["SaveResult"] = "Your product has been added!"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Product could not be added."); return(View(model)); }
public async Task PostProductTest() { // Arrange var repository = this.CreateRepository(); ProductCreate product = new ProductCreate { Name = "Product", Price = 275, Description = "Description", ImgUri = new Uri("http\\\\web.com\\ghh.png", UriKind.RelativeOrAbsolute) }; // Act var result = await repository.PostProduct(product).ConfigureAwait(false); // Assert Assert.NotNull(result); Assert.Equal(product.Price, result.Price); Assert.True(await repository.ProductExists(result.Id).ConfigureAwait(false)); }
public bool CreateProduct(ProductCreate model) { var entity = new Product() { CreatorId = _userId, AuthorId = model.AuthorId, Title = model.Title, Genre = model.Genre, Volume = model.Volume, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Products.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateProduct(ProductCreate model) { var entity = new Product() { ProductName = model.ProductName, ProductCategoryId = model.ProductCategoryId, ProductDescription = model.ProductDescription, ProductQuantity = model.ProductQuantity, ProductStartTime = model.ProductStartTime, ProductCloseTime = model.ProductCloseTime, ProductSeller = _userId.ToString(), MinimumSellingPrice = model.MinimumSellingPrice }; using (var ctx = new ApplicationDbContext()) { ctx.Product.Add(entity); return(ctx.SaveChanges() == 1); } }
public async Task <bool> CreateProductAsync(ProductCreate model) { var entity = new Product() { OwnerId = _userId, ProductName = model.ProductName, ProductDescription = model.ProductDescription, ProductPrice = model.ProductPrice, ProductCategory = (Data.Category)model.ProductCategory, ProductImage = model.ProductImage, ProductQuantity = model.ProductQuantity }; using (var ctx = new ApplicationDbContext()) { ctx.Products.Add(entity); return(await ctx.SaveChangesAsync() == 1); } }
public ActionResult Create(ProductCreate product) { if (!ModelState.IsValid) { return(View(product)); } var service = CreateProductService(); if (service.CreateProduct(product)) { TempData["SaveResult"] = "Product was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Product could not be created."); return(View(product)); }
public bool CreateProduct(ProductCreate model) { //Total Price Calculation var totalPrice = model.ProductPrice * model.Quantity; var entity = new Product() { OwnerId = _userId, ProductName = model.ProductName, ProductPrice = model.ProductPrice, Quantity = model.Quantity, TotalPrice = totalPrice }; using (var ctx = new ApplicationDbContext()) { ctx.Products.Add(entity); return(ctx.SaveChanges() == 1); } }
public async Task <WebApiResult> CreateProduct([FromBody] ProductCreate productCreate) { try { var createdProduct = await _productsService.CreateProductAsync <Product>(productCreate); var result = new WebApiResult { Data = createdProduct, StatusCode = HttpStatusCode.OK, Message = "Success" }; return(result); } catch (Exception ex) { _logger.LogError(ex, $"Error occured while creating product with id {productCreate.ProductId}", null); var exceptionMessageBuilder = new StringBuilder($"Error: {ex.Message};"); var innerException = ex?.InnerException; while (innerException != null) { exceptionMessageBuilder.Append($"{ex.InnerException};"); innerException = innerException.InnerException; } var result = new WebApiResult { Data = null, StatusCode = HttpStatusCode.InternalServerError, Message = exceptionMessageBuilder.ToString() }; return(result); } }
public bool CreateProduct(ProductCreate model) { var entity = new Product { OwnerId = _userId, ProductId = model.ProductId, ProductName = model.ProductName, ProductCategory = model.ProductCategory, ProductCost = model.ProductCost, ProductDescription = model.ProductDescription, ProductPrice = model.ProductPrice, ProductQuantity = model.ProductQuantity, ProductUpc = model.ProductUpc, }; using (var ctx = new ApplicationDbContext()) { ctx.Products.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateProduct(ProductCreate model) { var entity = new Product() { ProductName = model.ProductName, ProductDescription = model.ProductDescription, TypeOfCategory = (CategoryType)model.TypeOfCategory, Price = model.Price, IsFairTradeUSACertified = model.IsFairTradeUSACertified, IsGreenSealCertified = model.IsGreenSealCertified, IsLeapingBunnyCertified = model.IsLeapingBunnyCertified, IsRainForestAllianceCertified = model.IsRainForestAllianceCertified, CompanyId = model.CompanyId, CreatedUtc = DateTime.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Products.Add(entity); return(ctx.SaveChanges() == 1); } }
public void ProductCreate_With_Id_Null() { //Arrange var unit = new Unit { available = true, id = "001-001-001", originalPrice = new Price { value = 100, currency = "EUR", formatted = "€100" }, price = new Price { value = 100, currency = "EUR", formatted = "€100" }, size = "38", stock = 5 }; var pc = new ProductCreate { Color = "red", Id = null, ModelId = "001-001", Genders = new int[] { 0 }, Name = "test", Season = "Winter", SeasonYear = "2018", Units = new Unit[] { unit } }; //Act var actual = pc.Validate(); //Assert Assert.AreEqual(1, actual.Count()); Assert.AreEqual(ProductCreate.IdCantBeNull.ToString(), actual.First()); }
static void TestProducts() { // Get Category. Category category = _context.FindCategoryByName("Main Category"); // List all Products by Name. List <Product> list = _context.Products.OrderBy(x => x.Name).ToList(); // Create a new Product. Product prod1 = new ProductCreate(_context) .SetCategory(category) .SetName("Product 1") .SetVat(9) .SetPrice(10) .Execute(); // Create another Product. Product prod2 = new ProductCreate(_context) .SetCategory(category) .SetName("Product 2") .SetVat(18) .SetPrice(100) .Execute(); // Edit the first Product. new ProductEdit(_context, prod1) .SetName("Awesome Product") .Execute(); // Delete the second Product. _context.Products.Remove(prod2); _context.SaveChanges(); list = _context.Products.OrderBy(x => x.Name).ToList(); list = null; // Place to put a break-point. }
static void Main(string[] args) { var mainMenu = new MainView(); var customerViewType = new CustomerSubMenuView(); var run = true; while (run) { ConsoleKeyInfo userInput = mainMenu.MainMenu(); switch (userInput.KeyChar) { case '0': run = false; break; case '1': //Add Customer break; case '2': // Select Customer var viewAllCustomers = new AllCustomersView(); _selectedCustomer = viewAllCustomers.SelectActiveCustomer(); var customerSubMenu = new CustomerSubMenuView(); ConsoleKeyInfo userOption = customerSubMenu.CustomerSubMenu(); switch (userOption.KeyChar) { case '1': //Buyer Menu break; case '2': //Seller Menu var sellerMenu = new SellerMenuView(); ConsoleKeyInfo sellerInput = sellerMenu.SellerMenu(); switch (sellerInput.KeyChar) { case '1': //Add Product var addProductView = new ProductCreateView(); var customerId = (_selectedCustomer.CustomerId); var productTitle = addProductView.GetProdcutTitle(); var productPrice = addProductView.GetProdcutPrice(); var productQuantity = addProductView.GetProdcutQuantity(); var addProduct = new ProductCreate(); var newProduct = addProduct.AddNewProduct(customerId, productTitle, productPrice, productQuantity); break; case '2': //Delete Product break; case '3': //View Revenu Report break; default: break; } break; default: break; } break; case '3': break; default: break; } } }
public IHttpActionResult Create(ProductCreate product) { _productService.Create(product); return(Ok()); }
public void CreateNewDocument() { var newCatalog = service.CreateCatalog("catalog test").Result; var newBrand = service.CreateBrand("super brand", 1).Result; var newCategory = service.CreateCategory("test catalog", newCatalog.Contents.Identifier, 1, true, true, 1).Result; var newPriceList = service.CreatePriceList("christmasPriceList", Guid.NewGuid().ToString()).Result; List <ProdImage> productImages = new List <ProdImage> { new ProdImage { AltText = "this is an image", ExternalIdentifier = "", IsEnabled = true, IsPrimary = true, SortOrder = 1, SourceUrl = "https://s3.amazonaws.com/dfs-allpoints-multisite-test-images/product-images/21000237-423-01-01.jpg" } }; ProdShipping prodShipping = new ProdShipping { FreightClass = "143.90", IsFreeShip = true, IsFreightOnly = false, IsQuickShip = true, WeightActual = "11.98", WeightDimensional = "15.28", Height = "9.4", Width = "6.33", Length = "14" }; List <Guid> altBrands = new List <Guid> { Guid.NewGuid(), //random guids Guid.NewGuid() //rangom guids }; List <Specification> prodSpecs = new List <Specification> { new Specification { Name = "name", Value = "value" } }; List <PossibleFacetValue> possibleValues = new List <PossibleFacetValue> { new PossibleFacetValue("FACET 1", 1) }; ProductCreate productContent = new ProductCreate { BrandSku = "5HP012828", Cost = "58.0", Name = "test name", Description = "test description", ProductCode = "UAT12828", Prop65Message = "this is dangerous, click here", PrimaryBrandId = newBrand.Contents.Identifier, IsPurchaseable = true, Images = productImages, Shipping = prodShipping, AltBrands = altBrands, Specifications = prodSpecs }; var newFacet = service.CreateFacet("name of facet", 1, possibleValues).Result; var newProduct = service.CreateProduct(productContent).Result; var newPrice = service.CreatePrice(newPriceList.Contents.Identifier, newProduct.Contents.Identifier, null).Result; var newOffering = service.CreateOffering("frozen turkey", "explosive turkey", newProduct.Contents.Identifier, newCategory.Contents.Identifier).Result; Assert.IsNotNull(newBrand); Assert.IsTrue(newBrand.Contents.FullName == "super brand"); Assert.IsNotNull(newProduct); Assert.IsNotNull(newPriceList); Assert.IsTrue(newPriceList.Contents.Name == "christmasPriceList"); Assert.IsNotNull(newPrice); Assert.IsTrue(newOffering.Contents.FullName.Equals("explosive turkey")); Assert.IsNotNull(newOffering); }
public IHttpActionResult Create(ProductCreate model) { var product = _productService.Create(model); return(CreatedAtRoute("ProductApi", new { Id = product.Id }, product)); }
public HttpResponse <ResponseModels.Product> CreateProduct(ProductCreate requestModel) { return(new ApiHttpClient().PostRequest <ResponseModels.Product>(string.Format(ApiUrls.Product, string.Empty), AppSettings.SecretKey, requestModel)); }
public IActionResult CreateProduct([FromBody] ProductCreate _) { return(new OkObjectResult(new Product())); }
public IActionResult Create() { var model = new ProductCreate(context); return(View(model)); }
public ActionResult Create(ProductCreate Model) { var chkimg = 0; var imgList = new List <int>(); if (Model.MaxPrice <= Model.MinPrice) { ModelState.AddModelError("", "最高價不應該低於最低價"); return(View()); } try { var u = UserId; var product = db.Products.Add(new Products { Name = Model.Name, Description = Model.description, MinPrice = Model.MinPrice, MaxPrice = Model.MaxPrice, Enable = true, UserId = u }); if (Request["chkimg"] != null) { chkimg = int.Parse(Request["chkimg"].ToString()); } if (Request["hidimages"] != null) { imgList = Request["hidimages"].ToString().Split(',').Select(Int32.Parse).ToList(); } var tempimg = (from temp in db.temp_image where imgList.Contains(temp.ID) select temp).ToList(); foreach (var temp in tempimg) { if (temp.ID == chkimg) { db.Product_Images.Add(new Product_Images { Image_Byte = temp.image_Byte, Image_Path = temp.image_Path, IsPrimary = true, Product_Id = product.ID }); var image_handel = new ImageHandle(); var newImage = image_handel.BufferToImage(temp.image_Byte); var img = image_handel.ResizeImage(newImage, 500, 600); var filename = Guid.NewGuid().ToString(); var imagpath = image_handel.path + filename + ".jpeg"; img.Save(Server.MapPath(imagpath)); db.HomeImage.Add(new HomeImage { Image_Bytes = image_handel.ImageToBuffer(newImage, System.Drawing.Imaging.ImageFormat.Jpeg), Image_Path = imagpath, Product_Id = product.ID }); } else { db.Product_Images.Add(new Product_Images { Image_Byte = temp.image_Byte, Image_Path = temp.image_Path, IsPrimary = false, Product_Id = product.ID, }); } } db.SaveChanges(); } catch { return(View()); } return(RedirectToAction("Create")); }
public override Task <ProductInfo> AddProduct(ProductCreate request, ServerCallContext context) { return(base.AddProduct(request, context)); }
public async Task <ApiResult <int> > Create(ProductCreate bundle) { var pack = new List <Pack>(); pack.Add(new Pack() { Name = bundle.NamePackDefault, Value = 1, PackType = PackType.Product, Default = true }); if (bundle.NamePack != null) { int i = 0; foreach (string item in bundle.NamePack) { pack.Add(new Pack() { Name = item, Value = bundle.ValuePack[i], PackType = PackType.Product, Default = false }); i++; } } var product = new Product() { Code = bundle.Code, Name = bundle.Name, Description = bundle.Description, IdProductType = bundle.IdProductType, Packs = pack }; if (bundle.Min != null && bundle.Max != null) { product.Reminder = true; product.Min = bundle.Min; product.Max = bundle.Max; product.ReminderStartDate = (DateTime)bundle.ReminderStartDate; product.ReminderEndDate = (DateTime)bundle.ReminderEndDate; } var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.Code); var stt = 1; Location: var location = code.Location + stt; var str = code.Name + location; var checkCode = await _context.Products.AnyAsync(x => x.Code == str); if (checkCode) { stt++; goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); product.Code = str; _context.Products.Add(product); await _context.SaveChangesAsync(); // số bản ghi nếu return return(new ApiSuccessResult <int>(product.Id)); }
public JsonResult OnPostCreate(ProductCreate create) { var result = _productApplication.Create(create); return(new JsonResult(result)); }