Example #1
0
 public ActionResult Create(FormCollection frm)
 {
     try
     {
         stockStatu stk = new stockStatu();
         stk.pId = Convert.ToInt32(frm["urunsec"]);
         datas.stockStatus.Add(stk);
         datas.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Example #2
0
        public ActionResult Create(FormCollection frm)
        {
            if (user == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            product blg = new product();


            blg.name       = frm["prod.name"].ToString();
            blg.price      = Convert.ToDecimal(frm["prod.price"]);
            blg.desciption = frm["prod.desciption"].ToString();
            blg.smdesc     = frm["prod.smdesc"].ToString();
            blg.cId        = Convert.ToInt32(frm["basliksec"]);


            datas.products.Add(blg);

            datas.SaveChanges();

            if (Request.Files.Count > 0)
            {
                image img = new image();

                string path = Server.MapPath("/");



                if (Directory.Exists(path + "/productImg") == false)
                {
                    Directory.CreateDirectory(path + "productImg/");
                }

                if (!string.IsNullOrEmpty(Request.Files["pic"].FileName))
                {
                    Request.Files["pic"].SaveAs(path + "productImg/" + Request.Files["pic"].FileName);
                }
                img.folderName = string.IsNullOrEmpty(Request.Files["pic"].FileName) == true ? "" : "productImg/" + Request.Files["pic"].FileName;

                if (Request.Files["pic2"].FileName != null)
                {
                    if (!string.IsNullOrEmpty(Request.Files["pic2"].FileName))
                    {
                        Request.Files["pic2"].SaveAs(path + "productImg/" + Request.Files["pic2"].FileName);
                    }
                    img.folderName1 = string.IsNullOrEmpty(Request.Files["pic2"].FileName) == true ? "" : "productImg/" + Request.Files["pic2"].FileName;
                }

                if (Request.Files["pic3"].FileName != null)
                {
                    if (!string.IsNullOrEmpty(Request.Files["pic3"].FileName))
                    {
                        Request.Files["pic3"].SaveAs(path + "productImg/" + Request.Files["pic3"].FileName);
                    }
                    img.folderName2 = string.IsNullOrEmpty(Request.Files["pic3"].FileName) == true ? "" : "productImg/" + Request.Files["pic3"].FileName;
                }
                img.pid = datas.products.Max(q => q.Id);
                datas.images.Add(img);

                stockStatu abc = new stockStatu();
                abc.pId = datas.products.Max(q => q.Id);
                datas.stockStatus.Add(abc);
                datas.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }