public ActionResult SyncData()
        {
            StringBuilder s = new StringBuilder();

            if (ClsData.btnSync == "")
            {
                ClsData.btnSync = Conn.getInfo("select HoTen from NhanVien where MaNV=" + int.Parse(CookieCls.GetMaNV()) + "");

                if (ClsData.listRequest.Count > 0)
                {
                    string insertdata = "";
                    for (int i = 0; i < ClsData.listRequest.Count; i++)
                    {
                        insertdata += "insert into rssNews(rssID,NewspaperMenuId,Title,IconRss,IconSave,Link,[Description],Summary,rssDate,DateInput,Effect,MaNV) values(" + string.Join(",", ClsData.listRequest[i]) + "," + CookieCls.GetMaNV() + ")";
                    }
                    Conn.InsertBatch(insertdata);
                }
                ClsData.ClearArray();

                db.mProcesses.RemoveRange(db.mProcesses);
                db.SaveChanges();
                //Conn.UpdateRowData("delete from mProcess");
            }
            return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "rssID,NewspaperMenuId,Title,IconRss,IconSave,Link,Description,Summary,rssDate,DateInput,HotNews,PopularNews,MoreNews,Effect,MaNV")] rssNew rssNew)
        {
            if (ModelState.IsValid)
            {
                db.rssNews.Add(rssNew);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(rssNew));
        }
        public ActionResult DisplayWeb(string IDMenu, string DisplayWeb)
        {
            int         ID = int.Parse(IDMenu);
            LMenuByLeft mn = db.LMenuByLefts.SingleOrDefault(r => r.IDMenu == ID);

            if (mn != null)
            {
                mn.DisplayWeb = DisplayWeb == "true" ? true : false;
            }
            db.SaveChanges();
            return(Json("1", JsonRequestBehavior.AllowGet));
        }
        public ActionResult INSERT_MENU1(string sNAME)
        {
            wMenu1 m1  = new wMenu1();
            int    mID = db.wMenu1.Select(x => x.mID).DefaultIfEmpty(0).Max() + 1;
            int?   stt = db.wMenu1.Select(x => x.STT).DefaultIfEmpty(0).Max() + 1;

            m1.mID    = mID;
            m1.Name   = sNAME;
            m1.Effect = true;
            m1.STT    = stt;
            db.wMenu1.Add(m1);
            db.SaveChanges();
            return(Json("1", JsonRequestBehavior.AllowGet));
        }
        public ActionResult SetFunc(int sMaDM, string sMaCN, string sMaNV, string sCHK)
        {
            sMaNV = sMaNV.ToLower();
            sMaNV = sMaNV.Replace(",undefined", "");
            sMaNV = sMaNV.Replace(",on", "");
            sMaNV = sMaNV.Replace(",false", "");
            sMaNV = sMaNV.Replace(",true", "");

            string[] nd  = sMaNV.Split(',');
            int      len = nd.Length;

            if (len > 0)
            {
                for (int y = 1; y < len; y++)
                {
                    int manv       = int.Parse(nd[y].ToString());
                    var check_nvcn = from a in db.NhanVienChucNangs
                                     where a.MaNV == manv && a.MaDM == sMaDM && a.MaCN.Equals(sMaCN)
                                     select a;
                    var check_nvcn2 = from a in db.NhanVienChucNangs
                                      where a.MaNV == manv && a.MaDM == sMaDM
                                      select a;

                    if (check_nvcn.Count() > 0)
                    {
                        db.NhanVienChucNangs.RemoveRange(db.NhanVienChucNangs.Where(d => d.MaNV == manv && d.MaDM == sMaDM && d.MaCN.Equals(sMaCN)));
                    }
                    if (check_nvcn2.Count() > 0)
                    {
                        db.PhanQuyens.RemoveRange(db.PhanQuyens.Where(d => d.MaNV == manv && d.MaDM == sMaDM));
                    }

                    var nvcn = from a in db.NhanVienChucNangs
                               where a.MaNV == manv && a.MaDM == sMaDM && a.MaCN.Equals(sMaCN)
                               select a;
                    if (nvcn.Count() == 0 && sCHK == "true")
                    {
                        var checkpq = from a in db.PhanQuyens
                                      where a.MaDM == sMaDM && a.MaNV == manv
                                      select a;
                        if (checkpq.Count() == 0)
                        {
                            PhanQuyen pq = new PhanQuyen();
                            pq.MaDM = sMaDM;
                            pq.MaNV = manv;
                            db.PhanQuyens.Add(pq);
                        }

                        NhanVienChucNang tb = new NhanVienChucNang();
                        tb.MaNV = manv;
                        tb.MaDM = sMaDM;
                        tb.MaCN = sMaCN;
                        db.NhanVienChucNangs.Add(tb);
                    }
                    db.SaveChanges();
                }
            }
            return(Json("1", JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "NewsId,Title,Content")] News news, FormCollection collectedValues)
        {
            var user = Session["bhuinfologgedinuser"] as AppUser;

            if (ModelState.IsValid)
            {
                HttpPostedFileBase firstImage  = Request.Files["firstimage"];
                HttpPostedFileBase secondImage = Request.Files["secondimage"];
                HttpPostedFileBase thirdImage  = Request.Files["thirdimage"];
                if (user != null)
                {
                    if (thirdImage != null && (secondImage != null && (firstImage != null && (firstImage.FileName != "" || secondImage.FileName != "" || thirdImage.FileName != ""))))
                    {
                        news.DateCreated      = DateTime.Now;
                        news.DateLastModified = DateTime.Now;
                        news.NewsCategoryId   = long.Parse(collectedValues["NewsCategory"]);
                        news.CreatedById      = user.AppUserId;
                        news.LastModifiedById = user.AppUserId;
                        news.Likes            = 0;
                        news.Dislikes         = 0;
                        news.NewsView         = 0;
                        news.LastModifiedById = user.AppUserId;
                        news.Image            = firstImage.FileName != "" ? new FileUploader().UploadFile(firstImage, UploadType.NewsImage) : null;
                        news.SecondImage      = secondImage.FileName != "" ? new FileUploader().UploadFile(secondImage, UploadType.NewsImage) : null;
                        news.ThirdImage       = thirdImage.FileName != "" ? new FileUploader().UploadFile(thirdImage, UploadType.NewsImage) : null;
                        _db.News.Add(news);
                        _db.SaveChanges();
                        TempData["news"]             = "The article has been created Succesfully!";
                        TempData["notificationtype"] = NotificationType.Success.ToString();
                    }
                    else
                    {
                        TempData["news"]             = "Please Upload at least one image and try again!";
                        TempData["notificationtype"] = NotificationType.Danger.ToString();
                    }
                }
                else
                {
                    TempData["login"]            = "******";
                    TempData["notificationtype"] = NotificationType.Info.ToString();
                    return(RedirectToAction("Index"));
                }
                return(RedirectToAction("Index"));
            }
            TempData["news"]             = "Make sure you fill all the fields!";
            TempData["notificationtype"] = NotificationType.Danger.ToString();
            return(RedirectToAction("Create", "News", news));
        }
Exemplo n.º 7
0
        public JsonResult DeleteNews(long id)
        {
            var response = new JsonResponse();

            try
            {
                using (var cxt = new NewsDataContext())
                {
                    News newsModel = null;
                    newsModel = cxt.News.Find(id);
                    if (newsModel != null)
                    {
                        cxt.News.Remove(newsModel);

                        response.Success = true;
                        response.Result  = "Success";

                        cxt.SaveChanges();
                    }

                    response.Result = "Элемент не найден";
                }
            }
            catch (Exception e)
            {
                response.Result = "Error" + e.Message;
            }

            return(Json(response));
        }
Exemplo n.º 8
0
        public JsonResult CreateNews(NewsModel model)
        {
            var  response = new JsonResponse();
            News newModel = null;

            try
            {
                using (var cxt = new NewsDataContext())
                {
                    newModel       = Mapper.Map <NewsModel, News>(model);
                    newModel.Theme = new Theme()
                    {
                        Name = model.ThemeName
                    };

                    cxt.News.Add(newModel);
                    response.Success = true;
                    response.Result  = "Success";
                    cxt.SaveChanges();
                }
            }
            catch (Exception e)
            {
                response.Result = e.Message;
            }
            RedirectToAction("Index");
            return(Json(response));
        }
Exemplo n.º 9
0
        public ActionResult ViewNewsDetails(string Id)
        {
            var newsId = Convert.ToInt64(new Md5Ecryption().DecryptPrimaryKey(Id, true));

            if (ModelState.IsValid)
            {
                var news       = new NewsDataFactory().GetNewsById(Convert.ToInt64(newsId));
                var newsUpdate = _db.News.Find(newsId);
                newsUpdate.NewsView         = newsUpdate.NewsView + 1;
                _db.Entry(newsUpdate).State = EntityState.Modified;
                _db.SaveChanges();
                return(View("ViewNewsDetails", news));
            }
            var newsToRedirect = _db.News.Find(newsId);

            return(View(newsToRedirect));
        }
Exemplo n.º 10
0
        public ActionResult UpdateGhiChu(string STID, string SLID, string STNAME)
        {
            GhiChuCT cn = db.GhiChuCTs.SingleOrDefault(r => r.TID.Equals(STID) && r.LID.Equals(SLID));

            if (cn != null)
            {
                cn.TName = STNAME;
            }
            else
            {
                cn       = new GhiChuCT();
                cn.TID   = STID;
                cn.LID   = SLID;
                cn.TName = STNAME;
                db.GhiChuCTs.Add(cn);
            }
            db.SaveChanges();
            return(Json("1", JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 11
0
        public ActionResult CheckRight(string mID, string FRight)
        {
            int     smID = int.Parse(mID);
            wFormat mn   = db.wFormats.SingleOrDefault(r => r.mID == smID);

            if (mn != null)
            {
                mn.FRight = FRight == "true" ? true : false;
            }
            else
            {
                mn        = new wFormat();
                mn.mID    = smID;
                mn.TID    = 1;
                mn.FRight = FRight == "true" ? true : false;
                db.wFormats.Add(mn);
            }
            db.SaveChanges();
            return(Json("1", JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 12
0
        public ActionResult ChangPass(string MatKhau_old, string MatKhau_new)
        {
            int    manv      = int.Parse(CookieCls.GetMaNV());
            string passw_old = MyClss.Encode(MatKhau_old);
            string passw_new = MyClss.Encode(MatKhau_new);
            var    checkUser = from a in db.DangNhaps
                               where a.MaNV == manv && a.Pass.Equals(passw_old)
                               select a;

            if (checkUser.Count() <= 0)
            {
                return(Json("0", JsonRequestBehavior.AllowGet));//Pass old không đúng
            }
            else
            {
                var login = db.DangNhaps.Where(a => a.MaNV == manv).SingleOrDefault();
                login.Pass = passw_new;
                db.SaveChanges();
                return(Json("1", JsonRequestBehavior.AllowGet));//Update Pass success
            }
        }
Exemplo n.º 13
0
        public ActionResult SetFunc(string sNewspaperId, string sMaNV, string sCHK)
        {
            int newspaperid = int.Parse(sNewspaperId);
            int y           = 1;

            sMaNV = sMaNV.ToLower();
            sMaNV = sMaNV.Replace(",undefined", "");
            sMaNV = sMaNV.Replace(",on", "");
            sMaNV = sMaNV.Replace(",false", "");
            sMaNV = sMaNV.Replace(",true", "");

            string[] nd  = sMaNV.Split(',');
            int      len = nd.Length;

            if (len > 0)
            {
                for (y = 1; y < len; y++)
                {
                    int manv       = int.Parse(nd[y].ToString());
                    var newspapers = from a in db.PhanQuyenTBs
                                     where a.MaNV == manv && a.NewspaperId == newspaperid
                                     select a.NewspaperId;
                    if (newspapers.Count() > 0 && sCHK == "false")
                    {
                        db.PhanQuyenTBs.RemoveRange(db.PhanQuyenTBs.Where(r => r.MaNV == manv && r.NewspaperId == newspaperid));
                    }
                    else
                    {
                        PhanQuyenTB tb = new PhanQuyenTB();
                        tb.MaNV        = manv;
                        tb.NewspaperId = newspaperid;
                        db.PhanQuyenTBs.Add(tb);
                    }
                    db.SaveChanges();
                }
            }
            return(Json("1", JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 14
0
        public JsonResult NewsEdit(NewsModel model)
        {
            var response = new JsonResponse();
            var newModel = new News();

            try
            {
                using (var ctx = new NewsDataContext())
                {
                    newModel =
                        Mapper.Map <NewsModel, News>(model);
                    ctx.Entry(newModel).State = EntityState.Modified;
                    response.Success          = true;
                    response.Result           = "Success";
                    ctx.SaveChanges();
                }
            }
            catch (Exception e)
            {
                response.Result = "Error" + e.Message;
            }
            RedirectToAction("Index");
            return(Json(response));
        }
        public ActionResult INSERT_UPDATE_DANHMUC(string sLOAI, string sMADMCHA, string sTENMDC, string sSITE, string sHIENTHI, string sSTT, string sLID, string sMaDMCon, string Bien)
        {
            int smdmc = int.Parse(sMADMCHA);

            if (sLOAI == "dmcha")
            {
                string     cssClassCha = "menu-icon fa fa-th";
                DanhMucCha dmc         = db.DanhMucChas.SingleOrDefault(r => r.MaDMC == smdmc);
                if (dmc != null)
                {
                    dmc.ThuTu   = int.Parse(sSTT);
                    dmc.HienThi = (sHIENTHI == "true" ? true : false);
                    DanhMucChaCT dmcCT = db.DanhMucChaCTs.SingleOrDefault(r => r.MaDMC == smdmc && r.LID.Equals(sLID));
                    if (dmcCT != null)
                    {
                        dmcCT.TenDMC = sTENMDC;
                    }
                    else
                    {
                        dmcCT        = new DanhMucChaCT();
                        dmcCT.MaDMC  = smdmc;
                        dmcCT.LID    = sLID;
                        dmcCT.TenDMC = sTENMDC;
                        db.DanhMucChaCTs.Add(dmcCT);
                    }
                }
                else
                {
                    int madmcha = 0, madmcha_old = 0;
                    if (Bien == "0")
                    {
                        madmcha      = db.DanhMucChas.Select(x => x.MaDMC).DefaultIfEmpty(0).Max() + 1;
                        dmc          = new DanhMucCha();
                        dmc.MaDMC    = madmcha;
                        dmc.CssClass = cssClassCha;
                        dmc.ThuTu    = int.Parse(sSTT);
                        dmc.HienThi  = (sHIENTHI == "true" ? true : false);
                        db.DanhMucChas.Add(dmc);
                    }
                    else
                    {
                        madmcha_old = db.DanhMucChas.Select(x => x.MaDMC).DefaultIfEmpty(0).Max();
                    }
                    DanhMucChaCT dmcCT = db.DanhMucChaCTs.SingleOrDefault(r => r.MaDMC == (Bien == "0" ? madmcha : madmcha_old) && r.LID.Equals(sLID));
                    if (dmcCT != null)
                    {
                        dmcCT.TenDMC = sTENMDC;
                    }
                    else
                    {
                        dmcCT        = new DanhMucChaCT();
                        dmcCT.MaDMC  = (Bien == "0" ? madmcha : madmcha_old);
                        dmcCT.LID    = sLID;
                        dmcCT.TenDMC = sTENMDC;
                        db.DanhMucChaCTs.Add(dmcCT);
                    }
                }
            }
            else if (sLOAI == "dmcon")
            {
                int     smdmcon     = int.Parse(sMaDMCon);
                string  cssclassCon = "fm-user-secret";
                DanhMuc dm          = db.DanhMucs.SingleOrDefault(a => a.MaDM == smdmcon);
                if (dm != null)
                {
                    dm.Site    = sSITE;
                    dm.ThuTu   = int.Parse(sSTT);
                    dm.HienThi = (sHIENTHI == "true" ? true : false);

                    DanhMucCT dmCT = db.DanhMucCTs.SingleOrDefault(a => a.MaDM == smdmcon && a.LID.Equals(sLID));
                    if (dmCT != null)
                    {
                        dmCT.TenDM = sTENMDC;
                    }
                    else
                    {
                        dmCT      = new DanhMucCT();
                        dmCT.MaDM = smdmcon;
                        db.DanhMucCTs.Add(dmCT);
                    }
                }
                else
                {
                    int mdm = 0, madm_old = 0;
                    if (Bien == "0")
                    {
                        mdm        = db.DanhMucs.Select(a => a.MaDM).DefaultIfEmpty(0).Max() + 1;
                        dm         = new DanhMuc();
                        dm.MaDM    = mdm;
                        dm.MaDMC   = smdmc;
                        dm.Site    = sSITE;
                        dm.ThuTu   = int.Parse(sSTT);
                        dm.HienThi = (sHIENTHI == "true" ? true : false);
                        dm.Icon    = cssclassCon;
                        db.DanhMucs.Add(dm);
                    }
                    else
                    {
                        madm_old = db.DanhMucs.Select(a => a.MaDM).DefaultIfEmpty(0).Max();
                    }
                    DanhMucCT dmCT = db.DanhMucCTs.SingleOrDefault(a => a.MaDM == (Bien == "0" ? mdm : madm_old) && a.LID.Equals(sLID));
                    if (dmCT != null)
                    {
                        dmCT.TenDM = sTENMDC;
                    }
                    else
                    {
                        dmCT       = new DanhMucCT();
                        dmCT.MaDM  = (Bien == "0" ? mdm : madm_old);
                        dmCT.TenDM = sTENMDC;
                        dmCT.LID   = sLID;
                        db.DanhMucCTs.Add(dmCT);
                    }
                }
            }
            db.SaveChanges();
            return(Json("ins", JsonRequestBehavior.AllowGet));//Insert DMC
        }
Exemplo n.º 16
0
 public void Save() => _newsDataContextWrapper.SaveChanges();