public void AddAnItemToProductTable() { var product = new Product { Name = "Product4", CategoryId = 1, Description = "Description1", Price = 11, SupplierId = 1, }; var count = _productRepo.Add(product); Assert.Equal(1, count); Assert.Equal(4, product.Id); Assert.Equal(4, _productRepo.Table.Count()); }
public ActionResult Create(ProductModel prodModel) { if (Session["Login"] == null) { return(RedirectToAction("login", "Admin")); } try { if (ModelState.IsValid) { _prodRepo.Add(new Product() { Name = prodModel.Name, Description = prodModel.Description, Price = prodModel.Price, StockQty = prodModel.StockQty }); return(RedirectToAction("Index")); } else { return(View()); } } catch { // TODO log error ModelState.AddModelError("", "Something went wrong, please try again"); return(View()); } }
public ActionResult Create([Bind(Include = "Id,Description,Number,Price,Archieved")] Product product) { if (ModelState.IsValid) { db.Add(product); return(RedirectToAction("Index")); } return(View(product)); }
public async Task <ActionResult <Product> > PostProduct(Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repo.Add(product); return(CreatedAtAction("DisplayRoute", new { id = product.Id }, product)); }
public ActionResult CreateProduct([FromBody] Product pdata) { if (ModelState.IsValid) { _repo.Add(pdata); return(Ok(pdata.Id)); } else { return(BadRequest(ModelState)); } }
public async Task <int> AddProduct(AddUpdateProductRequestDto productRequestDto) { try { var response = _productRepo.Add(new Product { ProductName = productRequestDto.ProductName }); return(await response); } catch (Exception ex) { Console.WriteLine(ex); throw; } }
public IActionResult AddNew(ProductWriteDTO product) { if (product != null) { if (product.category_id != null) { product.category = _catrepo.GetOneById(product.category_id); Product productNew = _mapper.Map <Product>(product); _repo.Add(productNew); if (_repo.SaveChanges() > 0) { return(Ok("created")); } } } return(BadRequest()); }
public IActionResult Create([FromForm] ProductModel model) { try { var Product = new Product { Name = model.Name, Details = model.Details, Price = model.Price, Type = model.Type, }; repo.Add(Product); repo.save(); return(Ok()); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public async Task <bool> AddProduct(int userId, ProductDto productDto) { // TODO: [TESTS] (ProductService.AddProduct) Add tests // TODO: [VALIDATION] (ProductService.AddProduct) Ensure user owns this product var builder = new ServiceMetricBuilder(nameof(ProductService), nameof(AddProduct)) .WithCategory(MetricCategory.Product, MetricSubCategory.Add) .WithCustomInt1(userId) .WithCustomInt2(productDto.ClientId); try { using (builder.WithTiming()) { var productEntity = productDto.AsProductEntity(); productEntity.UserId = userId; using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); if (await _productRepo.Add(productEntity) <= 0) { return(false); } builder.WithResultsCount(1); return(true); } } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); return(false); } finally { await _metrics.SubmitPointAsync(builder.Build()); } }
public HttpResponseMessage Post(ProductModel model) { var result = _productRepo.Add(model); return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public int?SaveProduct(ProductModel product) { Product productData; try { if (product.ProductId <= 0) { productData = new Product(); } else { productData = _productRepo.Get(product.ProductId); } if (productData == null) { return(null); } productData.ProductName = product.ProductName; if (product.SubCategoryId != 0) { productData.CategoryId = product.SubCategoryId; } else { productData.CategoryId = product.CategoryId; } productData.Description = product.ProductDescription; productData.RetailPrice = product.RetailPrice; productData.Quantity += product.Quantity; productData.ShortDescription = product.ShortDescription; productData.Specifications = product.ProductSpecs; productData.UnitTypeId = product.UnitTypeId; productData.Status = CommonConstants.StatusTypes.Active; if (product.ProductId <= 0) { _productRepo.Add(productData); } else { _productRepo.Update(productData); } return(productData.ProductId); } catch (Exception ex) { _productUnitTypeRepo.Rollback(); _productRepo.Rollback(); _crashLogRepo.Add(new Crashlog { ClassName = "ProductService", MethodName = "SaveProduct", ErrorMessage = ex.Message, ErrorInner = ex.InnerException == null ? "" : ex.InnerException.Message, Data = JsonSerializer.Serialize(product), TimeStamp = DateTime.Now }); return(null); } }