Example #1
0
        public virtual ActionResult DeleteConfirmed(int id)
        {
            UnitProduct unitProduct = db.UnitProducts.Find(id);

            db.UnitProducts.Remove(unitProduct);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #2
0
 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));
 }
Example #3
0
        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));
        }
Example #5
0
        // 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));
        }
Example #6
0
        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());
        }
Example #7
0
        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;
            }));
        }
Example #8
0
 public void Update(UnitProduct unitProduct)
 {
     _unitProductRepository.Update(unitProduct);
 }
Example #9
0
 public UnitProduct Add(UnitProduct unitProduct)
 {
     return(_unitProductRepository.Add(unitProduct));
 }