예제 #1
0
        public ResponseModel EditNews(PAGE_CONTENT source)
        {
            try
            {
                using (BIGCCEntities ctx = new BIGCCEntities())
                {
                    var obj = ctx.PAGE_CONTENT.Where(o => o.ID == source.ID).First();
                    if (obj != null)
                    {
                        obj.SECTION_NAME     = source.SECTION_NAME;
                        obj.HTML_SUB_HEADER1 = source.HTML_SUB_HEADER1;
                        obj.HTML_VALUE       = source.HTML_VALUE;
                        if (source.IMAGE_URL1 != null)
                        {
                            obj.IMAGE_URL1 = source.IMAGE_URL1;
                            obj.IMAGE_URL2 = source.IMAGE_URL2;
                        }
                        ctx.SaveChanges();
                        resp.STATUS = true;
                    }
                    else
                    {
                        resp.ERROR_MESSAGE = "ไม่พบข้อมูล";
                    }
                }
            }
            catch (Exception ex)
            {
                resp.ERROR_MESSAGE = ex.Message;
            }

            return(resp);
        }
예제 #2
0
        public ResponseModel AddNews(PAGE_CONTENT source)
        {
            try
            {
                using (BIGCCEntities ctx = new BIGCCEntities())
                {
                    ctx.PAGE_CONTENT.Add(source);
                    ctx.SaveChanges();
                    resp.STATUS = true;
                }
            }
            catch (Exception ex)
            {
                resp.ERROR_MESSAGE = ex.Message;
            }

            return(resp);
        }
        public JsonResult AddNews()
        {
            ResponseModel          resp  = new ResponseModel();
            HttpFileCollectionBase files = Request.Files;
            var header     = Request.Form["SECTION_NAME"].ToString();
            var subHeader  = Request.Form["HTML_SUB_HEADER1"].ToString();
            var content    = Request.Form["HTML_VALUE"].ToString();
            var pathFolder = Server.MapPath("~/assets/images");

            try
            {
                //var pathFolder = Server.MapPath("~/assets/images/news");
                var pathfile = "";
                var fileName = "";
                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFileBase file = files[i];

                    pathfile = Path.Combine(pathFolder, file.FileName);
                    fileName = file.FileName;
                    file.SaveAs(pathfile);
                }

                NewsService service = new NewsService();

                if (Session["User"] != null)
                {
                    var          obj    = (LOGON)Session["User"];
                    PAGE_CONTENT source = new PAGE_CONTENT()
                    {
                        MODULE           = "News",
                        SECTION_NAME     = header,
                        HTML_SUB_HEADER1 = subHeader,
                        HTML_VALUE       = content,
                        STATUS           = 1,
                        IMAGE_URL1       = pathfile,
                        IMAGE_URL2       = fileName,
                        CREATED_DATE     = DateTime.Now,
                        UPDATED_DATE     = DateTime.Now,
                        CREATED_BY       = obj.USERNAME,
                        UPDATED_BY       = obj.USERNAME
                    };

                    resp = service.AddNews(source);
                }
                else
                {
                    resp.STATUS        = false;
                    resp.ERROR_MESSAGE = "กรุณาเข้าสู่ระบบใหม่";
                }
            }
            catch (Exception ex)
            {
                resp.STATUS        = false;
                resp.MESSAGE       = pathFolder;
                resp.ERROR_MESSAGE = ex.Message;
            }


            return(Json(resp, JsonRequestBehavior.AllowGet));
        }