Beispiel #1
0
        public ActionResult Insert(user user)
        {
            if (ModelState.IsValid)
            {
                if (user.id != null)
                {
                    user.created_at = DateTime.Now;
                    user.updated_at = null;
                    user.password   = user.password.PasswordEncryption();
                    try
                    {
                        db.users.Add(user);
                        db.SaveChanges();
                        ViewBag.tam     = 1;
                        ViewBag.Message = "Add data successfully!";
                    }
                    catch
                    {
                        ViewBag.tam     = 2;
                        ViewBag.Message = "Add data failed!";
                    }
                }
                else
                {
                    ViewBag.tam     = 2;
                    ViewBag.Message = "The input data is empty!";
                }
            }

            ViewBag.donvi = new SelectList(db.DonVis, "MS_DV", "TenDonVi", user.donvi);
            return(View(user));
        }
Beispiel #2
0
        public ActionResult Insert(loaitailieu loaitailieu)
        {
            if (ModelState.IsValid)
            {
                if (loaitailieu.MaLoai != null)
                {
                    loaitailieu.Create_at   = DateTime.Now;
                    loaitailieu.User_create = Session["user_id"].ToString();
                    try
                    {
                        db.loaitailieux.Add(loaitailieu);
                        db.SaveChanges();
                        ViewBag.tam     = 1;
                        ViewBag.Message = "Add data successfully!";
                    }
                    catch
                    {
                        ViewBag.tam     = 2;
                        ViewBag.Message = "Add data fail!";
                    }
                }
                else
                {
                    ViewBag.tam     = 2;
                    ViewBag.Message = "The input data is empty!";
                }
            }

            return(View(loaitailieu));
        }
        public ActionResult Insert(loaivanban loaivanban)
        {
            if (ModelState.IsValid)
            {
                if (loaivanban.TenLoaiVB != null)
                {
                    loaivanban.DateCreate = DateTime.Now;
                    loaivanban.DateUpdate = null;
                    try
                    {
                        db.loaivanbans.Add(loaivanban);
                        db.SaveChanges();
                        ViewBag.tam     = 1;
                        ViewBag.Message = "Add data successfully!";
                    }
                    catch
                    {
                        ViewBag.tam     = 2;
                        ViewBag.Message = "Add data fail!";
                    }
                }
                else
                {
                    ViewBag.tam     = 2;
                    ViewBag.Message = "The input data is empty!";
                }
            }

            return(View(loaivanban));
        }
Beispiel #4
0
        public ActionResult Insert(vanban vanban)
        {
            ViewBag.Idloaivb = new SelectList(db.loaivanbans, "id", "TenLoaiVB");
            if (ModelState.IsValid)
            {
                if (vanban.Sovb != null)
                {
                    ViewBag.tam      = 1;
                    vanban.Ngaydang  = DateTime.Now;
                    vanban.Nguoidang = Session["user_id"].ToString();
                    vanban.Donvigui  = Session["donvi"].ToString();
                    vanban.Noidung   = "";
                    vanban.Id        = Guid.NewGuid();
                    //upload file
                    var f = Request.Files["img[]"];
                    if (f != null && f.ContentLength > 0)
                    {
                        //string[] tam = f.FileName.Split('.');
                        //string filename = tam[0].Trim();

                        //string TenFile =  "_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + f.FileName.Substring(f.FileName.LastIndexOf("."));
                        string TenFile   = DateTime.Now.ToString("ddMMyyyyHHmmss") + "_" + f.FileName;
                        string pathfiles = Path.Combine(Server.MapPath("~/File/"), TenFile);
                        vanban.TenFile = TenFile;
                        vanban.Url     = "~/File/" + TenFile;
                        f.SaveAs(pathfiles);
                    }
                    else
                    {
                        vanban.Url = "";
                    }
                    db.vanbans.Add(vanban);
                    db.SaveChanges();
                    //ViewBag.Message = System.Text.Encoding.UTF8.GetBytes("Thêm dữ liệu thành công!");
                    ViewBag.Message = "Add data successfully!";
                }
                else
                {
                    ViewBag.tam     = 2;
                    ViewBag.Message = "The input data is empty!";
                }
            }

            ViewBag.Idloaivb = new SelectList(db.loaivanbans, "id", "TenLoaiVB", vanban.Idloaivb);
            return(View(vanban));
        }
Beispiel #5
0
        public ActionResult Status(Int16?id)
        {
            int res;

            if (id == null)
            {
                return(RedirectToAction("Index"));
            }
            loaitin loaitin = db.loaitins.Find(id);

            if (loaitin.status == 1)
            {
                //res_count = mod.Count_Status_Tl(id, 2);
                loaitin.status = 2;
                res            = mod.Update_Status_TT(id, 2);
            }
            else
            {
                loaitin.status = 1;
                res            = mod.Update_Status_TT(id, 1);
            }
            db.Entry(loaitin).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        [ValidateJsonAntiForgeryToken]//check token
        public JsonResult Deltrash(int?id)
        {
            bool result = false;

            try
            {
                tailieu tailieu = db.tailieux.Find(id);
                tailieu.status          = 0;
                db.Entry(tailieu).State = EntityState.Modified;
                db.SaveChanges();
                result = true;
            }
            catch
            {
                result = false;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Status(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }
            tintuc tintuc = db.tintucs.Find(id);

            if (tintuc.status == 1)
            {
                tintuc.status = 2;
            }
            else
            {
                tintuc.status = 1;
            }
            db.Entry(tintuc).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #8
0
        public ActionResult Status(int?id)
        {
            int res;

            if (id == null)
            {
                return(RedirectToAction("Index"));
            }
            theloai theloai = db.theloais.Find(id);

            if (theloai.status == 1)
            {
                theloai.status = 2;
                res            = mod.Update_Status_LT(id, 2);
            }
            else
            {
                theloai.status = 1;
                res            = mod.Update_Status_LT(id, 1);
            }
            db.Entry(theloai).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public void Commit()
 {
     _dbContext.SaveChanges();
 }
Beispiel #10
0
        public ActionResult Insert(PhanQuyen phanQuyen)
        {
            string Str_id = Request.Form["id"].ToString();

            if (ModelState.IsValid)
            {
                if (phanQuyen.id != null)
                {
                    if (phanQuyen.Quyen == false)//user
                    {
                        phanQuyen.mVanban     = true;
                        phanQuyen.mTheloaiTin = false;
                        phanQuyen.mLoaiTin    = false;
                        phanQuyen.mTinTuc     = false;
                        phanQuyen.mTaiLieu    = true;
                        phanQuyen.mGioiThieu  = false;
                        phanQuyen.mLienHe     = false;
                        phanQuyen.mLoaivanban = true;
                        phanQuyen.mQuantri    = false;
                    }
                    else
                    {
                        phanQuyen.mVanban     = true;
                        phanQuyen.mTheloaiTin = true;
                        phanQuyen.mLoaiTin    = true;
                        phanQuyen.mTinTuc     = true;
                        phanQuyen.mTaiLieu    = true;
                        phanQuyen.mGioiThieu  = true;
                        phanQuyen.mLienHe     = true;
                        phanQuyen.mLoaivanban = true;
                        phanQuyen.mQuantri    = true;
                    }
                    try
                    {
                        db.PhanQuyens.Add(phanQuyen);
                        db.SaveChanges();
                        ViewBag.tam     = 1;
                        ViewBag.Message = "Add data successfully!";
                    }
                    catch
                    {
                        ViewBag.tam     = 2;
                        ViewBag.Message = "Add data fail!";
                    }
                }
                else
                {
                    ViewBag.tam     = 2;
                    ViewBag.Message = "The input data is empty!";
                }
            }
            var user =
                db.users
                .Select(s => new
            {
                id       = s.id,
                username = s.id + " - " + s.name
            }).ToList();

            ViewBag.id = new SelectList(user, "id", "username");
            return(View(phanQuyen));
        }
        public ActionResult Insert(Banhanhvb banhanhvb)
        {
            string checkedCheckBoxes = Request.Form["checkbox"];

            string[]  arrListStr = checkedCheckBoxes.Split(',');
            string    Str_check  = Request.Form["Idvanban"].ToString();
            string    Nguoibh;
            Banhanhvb banhanhvb_db;

            DateTime Ngaybh;

            Nguoibh = Session["user_id"].ToString();
            Ngaybh  = DateTime.Now;
            if (!string.IsNullOrEmpty(checkedCheckBoxes))
            {
                for (int i = 0; i < arrListStr.Count(); i++)
                {
                    banhanhvb_db = new Banhanhvb();
                    switch (arrListStr[i])
                    {
                    case "1":
                        banhanhvb_db.Donvinhan = "1100000000";

                        break;

                    case "2":
                        banhanhvb_db.Donvinhan = "1101000000";
                        break;

                    case "3":
                        banhanhvb_db.Donvinhan = "1102000000";
                        break;

                    case "4":
                        banhanhvb_db.Donvinhan = "1103000000";

                        break;

                    case "5":
                        banhanhvb_db.Donvinhan = "1104000000";

                        break;

                    case "6":
                        banhanhvb_db.Donvinhan = "1105000000";

                        break;

                    case "7":
                        banhanhvb_db.Donvinhan = "1106000000";

                        break;

                    case "8":
                        banhanhvb_db.Donvinhan = "1107000000";

                        break;

                    case "9":
                        banhanhvb_db.Donvinhan = "1108000000";

                        break;

                    case "10":
                        banhanhvb_db.Donvinhan = "1109000000";

                        break;

                    case "11":
                        banhanhvb_db.Donvinhan = "1110000000";

                        break;

                    case "12":
                        banhanhvb_db.Donvinhan = "1111000000";

                        break;

                    case "13":
                        banhanhvb_db.Donvinhan = "1112000000";

                        break;

                    case "14":
                        banhanhvb_db.Donvinhan = "1113000000";

                        break;

                    case "15":
                        banhanhvb_db.Donvinhan = "1114000000";

                        break;

                    case "16":
                        banhanhvb_db.Donvinhan = "1115000000";

                        break;

                    case "17":
                        banhanhvb_db.Donvinhan = "1116000000";

                        break;

                    case "18":
                        banhanhvb_db.Donvinhan = "1117000000";

                        break;

                    case "19":
                        banhanhvb_db.Donvinhan = "1118000000";

                        break;

                    case "20":
                        banhanhvb_db.Donvinhan = "1124000000";

                        break;

                    case "21":
                        banhanhvb_db.Donvinhan = "1125000000";

                        break;

                    case "22":
                        banhanhvb_db.Donvinhan = "1128000000";

                        break;

                    case "23":
                        banhanhvb_db.Donvinhan = "1200000000";

                        break;

                    case "24":
                        banhanhvb_db.Donvinhan = "1300000000";

                        break;

                    default:
                        break;
                    }
                    if (ModelState.IsValid)
                    {
                        //var exists = db.Banhanhvbs.SingleOrDefault(x => x.Id == banhanhvb.Id) != null;
                        //if (db.Banhanhvbs.SingleOrDefault(x => x.Id == banhanhvb.Id) != null)
                        //{
                        //    banhanhvb.Id = Guid.NewGuid().ToString();
                        //}else
                        //{
                        //    db.Banhanhvbs.Add(banhanhvb);
                        //}

                        banhanhvb_db.Id           = Guid.NewGuid();
                        banhanhvb_db.Nguoibanhanh = Nguoibh;
                        banhanhvb_db.Ngayphathanh = Ngaybh;
                        banhanhvb_db.Idvanban     = Guid.Parse(Str_check);

                        db.Banhanhvbs.Add(banhanhvb_db);
                        db.SaveChanges();
                    }
                }
                ViewBag.Message = "Add data successfully!";
                ViewBag.tam     = 1;
            }
            else
            {
                ViewBag.tam     = 2;
                ViewBag.Message = "The input data is empty!";
            }
            var tieudes =
                db.vanbans
                .Select(s => new
            {
                Id       = s.Id,
                Sovb     = s.Sovb,
                Trichyeu = s.Trichyeu,
                Tieude   = s.Sovb + "-" + s.Trichyeu
            }).ToList();

            ViewBag.Idvanban = new SelectList(tieudes, "Id", "Tieude", Str_check);
            return(View());
        }