public ActionResult Create([Bind(Include = "ID,GUID,UserID,Ref,Publish1,Publish1_time,Publish2,Publish2_time,Type,Mime_type,Title,Category,Slug,Date,Body,Body2")] EP_POSTS EP_POST, int?return_id) { if (ModelState.IsValid) { EP_POSTS ep = db.EP_POST.Find(return_id); string guidval = ep.GUID; EP_POST.GUID = guidval; EP_POST.Ref = guidval; EP_POST.UserID = User.Identity.GetUserId(); EP_POST.Date = DateTime.Now; EP_POST.Type = "Post"; //Body 부분 인코딩 문제 해결을 위한 부분 //EP_POST.Body = HttpUtility.UrlEncode(EP_POST.Body); //byte[] bodytext = Encoding.GetEncoding("utf-8").GetBytes(EP_POST.Body); //EP_POST.Body = Encoding.GetEncoding("utf-8").GetString(bodytext); db.EP_POST.Add(EP_POST); db.SaveChanges(); return(RedirectToAction("Index", "Archive")); } return(View(EP_POST)); }
public ActionResult SaveByteArrayAsImage(string filename, string base64String) { try { byte[] bytes = Convert.FromBase64String(base64String); EP_POSTS EP_POST = new EP_POSTS(); Image image; using (MemoryStream ms = new MemoryStream(bytes)) { image = Image.FromStream(ms); } string newFileName = Guid.NewGuid().ToString(); string newFilePath = "/User/Posts/Image/" + newFileName + ".png"; string newFileLocation = HttpContext.Server.MapPath(newFilePath); if (Directory.Exists(Path.GetDirectoryName(newFileLocation)) == false) { Directory.CreateDirectory(Path.GetDirectoryName(newFileLocation)); } image.Save(newFileLocation, System.Drawing.Imaging.ImageFormat.Png); TransferImageDB(newFileName, EP_POST); return(Json(new { success = true, avatarFileLocation = newFilePath })); } catch (Exception ex) { return(Json(new { success = false, errorMessage = "Unable to save canvas.\nERRORINFO: " + ex.Message })); } }
private void TransferImageDB(string guid, [Bind(Include = "ID,GUID,UserID,Ref,Publish1,Publish1_time,Publish2,Publish2_time,Type,Mime_type,Title,Category,Slug,Date,Body")] EP_POSTS EP_POST) { EP_POST.GUID = guid; EP_POST.UserID = User.Identity.GetUserId(); EP_POST.Title = guid + ".png"; EP_POST.Body = guid + ".png"; EP_POST.Mime_type = "Image/png"; EP_POST.Date = DateTime.Now; EP_POST.Type = "Image"; db.EP_POST.Add(EP_POST); db.SaveChanges(); }
public ActionResult Edit([Bind(Include = "ID,Title,Category,Slug,Date,Body,Body2,UserID")] EP_POSTS EP_POST) { if (ModelState.IsValid) { EP_POST.UserID = User.Identity.GetUserId(); EP_POST.Date = DateTime.Now; EP_POST.Type = "Post"; db.Entry(EP_POST).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Archive")); } return(View(EP_POST)); }
public ActionResult Version(string title, string tag, string description, string save_count, int id, string table) { try { int return_id = 0; string guidval = Guid.NewGuid().ToString(); if (id != 0) { EP_POSTS ep = db.EP_POST.Find(id); string refguid = ep.GUID; EP_POSTS EP_POST = new EP_POSTS(); EP_POST.GUID = guidval; EP_POST.UserID = User.Identity.GetUserId(); EP_POST.Ref = refguid; EP_POST.Body = table; EP_POST.Body2 = description; EP_POST.Title = title; EP_POST.Date = DateTime.Now; EP_POST.Slug = tag; EP_POST.Type = "Version"; db.EP_POST.Add(EP_POST); db.SaveChanges(); } else if (id == 0) { EP_POSTS EP_POST = new EP_POSTS(); EP_POST.GUID = guidval; EP_POST.Ref = guidval; EP_POST.UserID = User.Identity.GetUserId(); EP_POST.Body = table; EP_POST.Body2 = description; EP_POST.Title = title; EP_POST.Date = DateTime.Now; EP_POST.Slug = tag; EP_POST.Type = "Version"; db.EP_POST.Add(EP_POST); db.SaveChanges(); return_id = EP_POST.ID; } return(Json(new { success = true, id = return_id })); } catch (Exception) { return(Json(new { success = false })); } }
public void SaveCate(EP_POSTS EP_POSTS) { IEnumerable <EP_METAS> metas = db.EP_META.ToList().Where(c => c.UserID == User.Identity.GetUserId()); if (metas != null) { foreach (EP_METAS meta in metas) { String Publish_BLOGID = meta.Publish_BLOGID; String service = meta.publish; String publish_SITE = meta.publish_SITE; String Publish_ID = meta.Publish_ID; String Publish_BLOGKEY = meta.Publish_BLOGKEY; String Publish_PW = meta.Publish_PW; if (meta.publish == "Tistory") { Category[] category; List <string> categorylist = new List <string>(); try { MetaWeblog api = new MetaWeblog(publish_SITE + "/api"); //api.newPost(Publish_BLOGID, Publish_ID, Publish_BLOGKEY, post, true); category = api.getCategories(Publish_BLOGID, Publish_ID, Publish_BLOGKEY); foreach (Category cate in category) { categorylist.Add(cate.title); } } catch { ModelState.AddModelError("", "실패했습니다."); } string catstring = categorylist.ToArray().Aggregate((cur, next) => cur + "|" + next); EP_POSTS.Title = publish_SITE; EP_POSTS.GUID = Guid.NewGuid().ToString(); EP_POSTS.UserID = User.Identity.GetUserId(); EP_POSTS.Date = DateTime.Now; EP_POSTS.Type = "Categories"; EP_POSTS.Mime_type = service; EP_POSTS.Category = catstring; db.EP_POST.Add(EP_POSTS); db.SaveChanges(); } if (meta.publish == "Naver") { Category[] category; List <string> categorylist = new List <string>(); try { MetaWeblog api = new MetaWeblog("https://api.blog.naver.com/xmlrpc"); //api.newPost(Publish_BLOGID, Publish_ID, Publish_BLOGKEY, post, true); category = api.getCategories(Publish_BLOGID, Publish_ID, Publish_BLOGKEY); foreach (Category cate in category) { categorylist.Add(cate.title); } } catch { ModelState.AddModelError("", "실패했습니다."); } string catstring = categorylist.ToArray().Aggregate((cur, next) => cur + "|" + next); EP_POSTS.Title = publish_SITE; EP_POSTS.GUID = Guid.NewGuid().ToString(); EP_POSTS.UserID = User.Identity.GetUserId(); EP_POSTS.Date = DateTime.Now; EP_POSTS.Type = "Categories"; EP_POSTS.Mime_type = service; EP_POSTS.Category = catstring; db.EP_POST.Add(EP_POSTS); db.SaveChanges(); } if (meta.publish == "WordPress") { Category[] category; List <string> categorylist = new List <string>(); try { MetaWeblog api = new MetaWeblog(publish_SITE + "/xmlrpc.php"); //api.newPost("", Publish_ID, Publish_PW, post, true); category = api.getCategories("1", Publish_ID, Publish_PW); foreach (Category cate in category) { categorylist.Add(cate.title); } } catch { ModelState.AddModelError("", "실패했습니다."); } string catstring = categorylist.ToArray().Aggregate((cur, next) => cur + "|" + next); EP_POSTS.Title = publish_SITE; EP_POSTS.GUID = Guid.NewGuid().ToString(); EP_POSTS.UserID = User.Identity.GetUserId(); EP_POSTS.Date = DateTime.Now; EP_POSTS.Type = "Categories"; EP_POSTS.Mime_type = service; EP_POSTS.Category = catstring; db.EP_POST.Add(EP_POSTS); db.SaveChanges(); } } } }