Ejemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "Khenthuong_id,ngaykhenthuong,hinhthuc,soquyetdinh,capkhenthuong,tochuc_id,scanurl")] Khenthuongtapthe khenthuongtapthe, HttpPostedFileBase uploadImage)
        {
            if (ModelState.IsValid)
            {
                if (uploadImage != null)
                {
                    //xoa anh cu

                    var filePath = Server.MapPath(Request["oldurl"]);
                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.File.Delete(filePath);
                    }

                    //nap anh moi
                    //string filename = Path.GetFileNameWithoutExtension(uploadImage.FileName);
                    string extension = Path.GetExtension(uploadImage.FileName);
                    string filename  = khenthuongtapthe.Khenthuong_id + DateTime.Now.ToString("yymmssfff") + extension;
                    khenthuongtapthe.scanurl = "/Image/Khenthuong/" + filename;
                    filename = Path.Combine(Server.MapPath("~/Image/Khenthuong/"), filename);
                    uploadImage.SaveAs(filename);
                }
                else
                {
                    khenthuongtapthe.scanurl = Request["oldurl"];
                }
                db.Entry(khenthuongtapthe).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.tochuc_id = new SelectList(db.CapCongDoans, "Capcongdoan_id", "name", khenthuongtapthe.tochuc_id);
            return(View(khenthuongtapthe));
        }
Ejemplo n.º 2
0
        // GET: Khenthuongtapthes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Khenthuongtapthe khenthuongtapthe = db.Khenthuongtapthes.Find(id);

            if (khenthuongtapthe == null)
            {
                return(HttpNotFound());
            }
            return(View(khenthuongtapthe));
        }
Ejemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Khenthuongtapthe khenthuongtapthe = db.Khenthuongtapthes.Find(id);
            //xoa anh cu
            var filePath = Server.MapPath(khenthuongtapthe.scanurl);

            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.Delete(filePath);
            }
            db.Khenthuongtapthes.Remove(khenthuongtapthe);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Khenthuongtapthe khenthuongtapthe = db.Khenthuongtapthes.Find(id);

            if (khenthuongtapthe == null)
            {
                return(HttpNotFound());
            }
            //phan quyen mod cap tren tro len co quyen
            var loggedInUser = System.Web.HttpContext.Current.User.Identity.GetUserId();

            if ((!db.CapCongDoans.Find(db.Khenthuongtapthes.Find(id).CapCongDoan.Capcongdoan_id).motaphancap.Contains(db.Users.Include(x => x.CapCongDoan).SingleOrDefault(x => x.Id == loggedInUser).CapCongDoan.motaphancap) && User.IsInRole("mod")))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            return(View(khenthuongtapthe));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "Khenthuong_id,ngaykhenthuong,hinhthuc,soquyetdinh,capkhenthuong,tochuc_id,scanurl")] Khenthuongtapthe khenthuongtapthe, HttpPostedFileBase uploadImage)
        {
            if (ModelState.IsValid)
            {
                if (uploadImage != null)
                {
                    //nap anh moi
                    //string filename = Path.GetFileNameWithoutExtension(uploadImage.FileName);
                    string extension = Path.GetExtension(uploadImage.FileName);
                    string filename  = khenthuongtapthe.Khenthuong_id + DateTime.Now.ToString("yymmssfff") + extension;
                    khenthuongtapthe.scanurl = "/Image/Khenthuong/" + filename;
                    filename = Path.Combine(Server.MapPath("~/Image/Khenthuong/"), filename);
                    uploadImage.SaveAs(filename);
                }

                db.Khenthuongtapthes.Add(khenthuongtapthe);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.tochuc_id = new SelectList(db.CapCongDoans, "Capcongdoan_id", "name", khenthuongtapthe.tochuc_id);
            return(View(khenthuongtapthe));
        }