Example #1
0
        public ActionResult Create(tablePRODUCT model)
        {
            if (ModelState.IsValid)
            {
                using (var scope = new TransactionScope())
                {
                    //Add Day
                    model.ngaynhap = DateTime.Today;

                    //Add model to database
                    db.tablePRODUCTs.Add(model);
                    db.SaveChanges();

                    //Save file to App_Data
                    var path = Server.MapPath("~/App_Data");
                    path = System.IO.Path.Combine(path, model.idSP.ToString());
                    Request.Files["Image"].SaveAs(path);

                    //Accept all and persistence
                    scope.Complete();
                    return(RedirectToAction("Index"));
                }
            }
            return(View(model));
        }
Example #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            tablePRODUCT tablePRODUCT = db.tablePRODUCTs.Find(id);

            db.tablePRODUCTs.Remove(tablePRODUCT);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #3
0
        // GET: Admin_tablePRODUCTs/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tablePRODUCT tablePRODUCT = db.tablePRODUCTs.Find(id);

            if (tablePRODUCT == null)
            {
                return(HttpNotFound());
            }
            return(View(tablePRODUCT));
        }
Example #4
0
        // GET: Admin_tablePRODUCTs/Edit/5
        public ActionResult Edit(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tablePRODUCT tablePRODUCT = db.tablePRODUCTs.Find(id);

            if (tablePRODUCT == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            ViewBag.idloaiSP = new SelectList(db.LoaiSanPhams.ToList().OrderBy(n => n.TenLoaiSP), "idloaiSP", "TenLoaiSP", tablePRODUCT.idLSP);
            ViewBag.MaNCC    = new SelectList(db.NHACUNGCAPs.ToList().OrderBy(n => n.TenNCC), "MaNCC", "TenNCC", tablePRODUCT.MaNCC);
            return(View(tablePRODUCT));
        }
Example #5
0
        public ActionResult Edit(tablePRODUCT model)
        {
            if (ModelState.IsValid)
            {
                using (var scope = new TransactionScope())
                {
                    var path = Server.MapPath("~/App_Data");
                    path = System.IO.Path.Combine(path, model.idSP.ToString());

                    UpdateModel(model);

                    db.Entry(model).State = EntityState.Modified;
                    db.SaveChanges();
                    scope.Complete();
                }
            }
            return(RedirectToAction("Index"));
        }