public async Task <ActionResult <ProductTb> > PostProductTb(ProductTb productTb)
        {
            _context.ProductTb.Add(productTb);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProductTb", new { id = productTb.ProductId }, productTb));
        }
        public async Task <IActionResult> PutProductTb(int id, ProductTb productTb)
        {
            if (id != productTb.ProductId)
            {
                return(BadRequest());
            }

            _context.Entry(productTb).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductTbExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        public ActionResult Product(ProductTb otb, FormCollection form)
        {
            string strDDLValue = form["Productgroupddl"].ToString();
            //string strDDLValue = Request.Form["Productgroupddl"].ToString();
            var uploadedfile = Request.Files[0];
            var filename     = Path.GetFileName(uploadedfile.FileName);
            var fileSavePath = Server.MapPath("/Content/DinamicPics/" + filename);

            uploadedfile.SaveAs(fileSavePath);
            otb.ProductPhotoUrl = "../../Content/DinamicPics/" + filename;

            //upload file

            var uploadedfile2 = Request.Files[1];
            var filename2     = Path.GetFileName(uploadedfile2.FileName);
            var fileSavePath2 = Server.MapPath("/Content/productFile/" + filename2);

            uploadedfile2.SaveAs(fileSavePath2);
            otb.ProductFile = "../../Content/productFile/" + filename2;

            // Upload File free

            var uploadedfile3 = Request.Files[2];
            var filename3     = Path.GetFileName(uploadedfile3.FileName);
            var fileSavePath3 = Server.MapPath("/Content/productFile/" + filename3);

            uploadedfile2.SaveAs(fileSavePath3);
            otb.ProductFreeFile   = "../../Content/productFile/" + filename3;
            otb.ProductIsSpeciall = false;
            otb.ProductStatus     = true;
            otb.ProductGroupIdFK  = int.Parse(strDDLValue);
            db.ProductTb.Add(otb);
            db.SaveChanges();
            ViewBag.Message = "عملیات با موفقیت انجام شد";

            ViewBag.ddlProductGroup = new SelectList(db.ProductGroupTb, "ProductGroupId", "ProductGroupTitle");
            return(View());
        }