public IHttpActionResult Put(int id, DTO_WEB_BaiViet tbl_WEB_BaiViet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tbl_WEB_BaiViet.ID)
            {
                return(BadRequest());
            }
            //#/bai-viet/12/gioi-thieu-phong-qm

            tbl_WEB_BaiViet.URL = "#/bai-viet/" + tbl_WEB_BaiViet.ID.ToString() + "/" +
                                  iData.Common.StringUtil.RemoveVietSignSpecialCharAndSpaceChar(tbl_WEB_BaiViet.Name);

            bool resul = BS_WEB_BaiViet.put_WEB_BaiViet(db, id, tbl_WEB_BaiViet, Username);

            if (resul)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(NotFound());
            }
        }
示例#2
0
        public static bool put_WEB_BaiViet(AppEntities db, int ID, DTO_WEB_BaiViet item, string Username)
        {
            bool result = false;
            var  dbitem = db.tbl_WEB_BaiViet.Find(ID);

            if (dbitem != null)
            {
                dbitem.IDDanhMuc       = item.IDDanhMuc;
                dbitem.IDParent        = item.IDParent;
                dbitem.Code            = item.Code;
                dbitem.Name            = item.Name;
                dbitem.Remark          = item.Remark;
                dbitem.Sort            = item.Sort;
                dbitem.IsDisabled      = item.IsDisabled;
                dbitem.IsDeleted       = item.IsDeleted;
                dbitem.Type            = item.Type;
                dbitem.ThumbnailImage  = item.ThumbnailImage;
                dbitem.Image           = item.Image;
                dbitem.AlternateImage  = item.AlternateImage;
                dbitem.NgayDangBaiViet = item.NgayDangBaiViet;
                dbitem.LuotXem         = item.LuotXem;
                dbitem.DanhGia         = item.DanhGia;
                dbitem.AllowComment    = item.AllowComment;
                dbitem.LuotThich       = item.LuotThich;
                dbitem.NgonNgu         = item.NgonNgu;
                dbitem.Summary         = item.Summary;
                dbitem.NoiDung         = item.NoiDung;
                dbitem.TenKhac         = item.TenKhac;
                dbitem.ReadMoreText    = item.ReadMoreText;
                dbitem.SEO1            = item.SEO1;
                dbitem.SEO2            = item.SEO2;
                dbitem.Duyet           = item.Duyet;
                dbitem.URL             = item.URL;
                dbitem.Pin             = item.Pin;
                dbitem.PinPos          = item.PinPos;
                dbitem.Home            = item.Home;
                dbitem.HomePos         = item.HomePos;

                dbitem.ModifiedBy   = Username;
                dbitem.ModifiedDate = DateTime.Now;

                try
                {
                    db.SaveChanges();

                    BS_CUS_Version.update_CUS_Version(db, null, "DTO_WEB_BaiViet", dbitem.ModifiedDate, Username);

                    result = true;
                }
                catch (DbEntityValidationException e)
                {
                    errorLog.logMessage("put_WEB_BaiViet", e);
                    result = false;
                }
            }
            return(result);
        }
示例#3
0
        public IHttpActionResult Post_UploadImage()
        {
            var httpRequest = System.Web.HttpContext.Current.Request;

            if (httpRequest.Files.Count < 1)
            {
                return(BadRequest(ModelState));
            }

            DTO_WEB_BaiViet result = new DTO_WEB_BaiViet();

            foreach (string file in httpRequest.Files)
            {
                #region upload file
                var postedFile = httpRequest.Files[file];

                string uploadPath = "/Uploads/WebImages/" + DateTime.Today.ToString("yyyy/MM/dd").Replace("-", "/");

                string oldName = System.IO.Path.GetFileName(postedFile.FileName);
                string ext     = oldName.Substring(oldName.LastIndexOf('.') + 1).ToLower();

                var    g        = Guid.NewGuid();
                string fileid   = g.ToString();
                string fileName = "" + fileid + "." + oldName;

                string mapPath          = System.Web.HttpContext.Current.Server.MapPath("~/");
                string strDirectoryPath = mapPath + uploadPath;
                string strFilePath      = strDirectoryPath + "/" + fileName;

                System.IO.FileInfo existingFile = new System.IO.FileInfo(strFilePath);

                if (!System.IO.Directory.Exists(strDirectoryPath))
                {
                    System.IO.Directory.CreateDirectory(strDirectoryPath);
                }
                if (existingFile.Exists)
                {
                    existingFile.Delete();
                    existingFile = new System.IO.FileInfo(strFilePath);
                }

                postedFile.SaveAs(strFilePath);

                result.Image = uploadPath + "/" + fileName;

                #endregion
            }


            if (result != null)
            {
                return(CreatedAtRoute("", new { id = result.ID }, result));
            }
            return(Conflict());
        }
        public IHttpActionResult Get(int id)
        {
            DTO_WEB_BaiViet tbl_WEB_BaiViet = BS_WEB_BaiViet.get_WEB_BaiViet(db, id);

            if (tbl_WEB_BaiViet == null)
            {
                return(NotFound());
            }

            return(Ok(tbl_WEB_BaiViet));
        }
        public IHttpActionResult Post(DTO_WEB_BaiViet tbl_WEB_BaiViet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DTO_WEB_BaiViet result = BS_WEB_BaiViet.post_WEB_BaiViet(db, tbl_WEB_BaiViet, Username);

            Put(result.ID, result);


            if (result != null)
            {
                return(CreatedAtRoute("get_WEB_BaiViet", new { id = result.ID }, result));
            }
            return(Conflict());
        }