public virtual ActionResult DeleteConfirmed(int id) { UnitProduct unitProduct = db.UnitProducts.Find(id); db.UnitProducts.Remove(unitProduct); db.SaveChanges(); return(RedirectToAction("Index")); }
public virtual ActionResult Edit([Bind(Include = "Id,Name")] UnitProduct unitProduct) { if (ModelState.IsValid) { db.Entry(unitProduct).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(unitProduct)); }
public virtual ActionResult Create([Bind(Include = "Id,Name")] UnitProduct unitProduct) { if (ModelState.IsValid) { db.UnitProducts.Add(unitProduct); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(unitProduct)); }
public virtual ActionResult Create([Bind(Include = "Id,Name")] UnitProduct unitProduct) { if (ModelState.IsValid) { MyUnitOfWork.UnitProductRepository.Insert(unitProduct); MyUnitOfWork.Save(); return(RedirectToAction("Index")); } return(View(unitProduct)); }
// GET: testUnitProducts/Delete/5 public virtual ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } UnitProduct unitProduct = db.UnitProducts.Find(id); if (unitProduct == null) { return(HttpNotFound()); } return(View(unitProduct)); }
public async Task <IActionResult> PostProduct([FromBody] CreateSubProduct subproduct, [FromRoute] string type) { if (ModelState.IsValid) { ProductCategory pc; BaseSubProduct sub; if (type == "unit") { sub = new UnitProduct() { ProductPrice = subproduct.ProductPrice, Name = subproduct.Name, Description = subproduct.Description, UnitCall = subproduct.UnitCall, UnitMetric = subproduct.UnitMetric, UnitValue = subproduct.UnitValue }; } else { sub = new SingleProduct { ProductPrice = subproduct.ProductPrice, Name = subproduct.Name, Description = subproduct.Description }; } if (subproduct.ProductCategoryID != 0) { pc = await _context.productCategories.FirstOrDefaultAsync(i => i.ProductCategoryID == subproduct.ProductCategoryID); sub.ProductCategory = pc; } await _context.SubProducts.AddAsync(sub); await _context.SaveChangesAsync(); return(Ok()); } return(BadRequest()); }
public HttpResponseMessage Create(HttpRequestMessage request, UnitProductViewModel unitProductVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { var newUnitProduct = new UnitProduct(); newUnitProduct.UpdateUnitProduct(unitProductVm); _unitProductService.Add(newUnitProduct); _unitProductService.Save(); var responseData = Mapper.Map <UnitProduct, UnitProductViewModel>(newUnitProduct); response = request.CreateResponse(HttpStatusCode.Created, responseData); } return response; })); }
public void Update(UnitProduct unitProduct) { _unitProductRepository.Update(unitProduct); }
public UnitProduct Add(UnitProduct unitProduct) { return(_unitProductRepository.Add(unitProduct)); }