public ActionResult Create([Bind(Include = "ID,Title,Body,Date,Type,ContentType")] Tutorial tutorial, HttpPostedFileBase upload) { string userid = User.Identity.GetUserId(); var currentuser = db.Users.SingleOrDefault(u => u.Id == userid); if (ModelState.IsValid) { if (upload != null && upload.ContentLength > 0) { var pic = new FileMain { FileName = System.IO.Path.GetFileName(upload.FileName), FileType = FileType.Pic, ContentType = upload.ContentType }; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { pic.Content = reader.ReadBytes(upload.ContentLength); } tutorial.FileMains = new List <FileMain> { pic }; } tutorial.User = currentuser; tutorial.Date = DateTime.Now; db.Tutorials.Add(tutorial); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tutorial)); }
//Loading public ActionResult Loading() { var code = Session["key"]; FileMain file = db.FileMains.SingleOrDefault(n => n.file_key == code.ToString()); return(View(db.FileMains.Find(file.file_id))); }
public ActionResult GetNewFileIdforMoveToProcess(string FileNo) { //RBACUser rUser = new RBACUser(Session["UserName"].ToString()); //if (!rUser.HasPermission("Group_Edit")) //{ // return Json("D", JsonRequestBehavior.AllowGet); //} try { FileMain FileMainAdd = new FileMain(); var data = _fileMainService.All().ToList().FirstOrDefault(x => x.FileNo == FileNo); var MainID = _fileMainService.All().ToList().Where(x => x.FileNo == FileNo).Select(x => x.MainID).FirstOrDefault(); string sql = string.Format(" Select fd.AttachFileName as FileName from FileDetail as fd where MainID= '" + MainID + "' " + " union select AttachFileName from FileTransDetail where FileTransID in " + "(select FileTransID from FileTransMain where MainID = '" + MainID + "')"); List <ProcessActionVM> VchrList; using (ERPConfigurationContext dbContext = new ERPConfigurationContext()) { VchrList = dbContext.Database.SqlQuery <ProcessActionVM>(sql).ToList(); } // ViewBag.Items = VchrList; if (data != null) { FileMainAdd = data; } return(Json(new { FileMainAdd, VchrList }, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json("0", JsonRequestBehavior.AllowGet)); } }
public ActionResult PostSubmit(HttpPostedFileBase fileread, FileMain fileMain) { if (fileread == null) { TempData["check"] = "Vui lòng bỏ văn bản vào để tiến hành"; return(Redirect("/")); } else { var code = Guid.NewGuid().ToString(); var fileimg = Path.GetFileName(fileread.FileName); var pa = Path.Combine(Server.MapPath("~/IMG/Img"), code + fileimg); fileread.SaveAs(pa); fileMain.file_key = code; fileMain.file_status = 1; fileMain.file_datecreate = DateTime.Now; fileMain.file_img = code + fileread.FileName; var dao = new FilesDAO(); var status = dao.create(fileMain); switch (status) { case 1: Session["key"] = code; FileMain f = db.FileMains.SingleOrDefault(n => n.file_key == code); History history = new History { file_id = f.file_id, his_title = "đã tạo báo cáo", his_datecreate = DateTime.Now, his_status = 1 }; db.Historys.Add(history); db.SaveChanges(); History history2 = new History { file_id = f.file_id, his_title = "đang tiến hành đọc", his_datecreate = DateTime.Now, his_status = 1 }; db.Historys.Add(history2); db.SaveChanges(); return(RedirectToAction("Loading")); default: return(Redirect("/")); } } }
public int create(FileMain fileMain) { try { db.FileMains.Add(fileMain); db.SaveChanges(); return(1); } catch (Exception) { return(2); } }
//public ActionResult Edit([Bind(Include = "ID,Title,Body,Date,Type,ContentType")] Tutorial tutorial, HttpPostedFileBase upload) public ActionResult Edit(Tutorial model, HttpPostedFileBase upload, int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tutorial tutorial = db.Tutorials.Find(id); if (tutorial == null) { return(HttpNotFound()); } if (ModelState.IsValid) { //int tutorialid = tutorial.ID; //var tutorialToUpdate = db.Tutorials.SingleOrDefault(u => u.ID == tutorialid); if (upload != null && upload.ContentLength > 0) { if (tutorial.FileMains.Any(f => f.FileType == FileType.Pic)) { db.FileMains.Remove(tutorial.FileMains.First(f => f.FileType == FileType.Pic)); } var pic = new FileMain { FileName = System.IO.Path.GetFileName(upload.FileName), FileType = FileType.Pic, ContentType = upload.ContentType }; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { pic.Content = reader.ReadBytes(upload.ContentLength); } tutorial.FileMains = new List <FileMain> { pic }; } tutorial.Title = model.Title; tutorial.Body = model.Body; tutorial.Type = model.Type; tutorial.ContentType = model.ContentType; tutorial.Date = DateTime.Now; db.Entry(tutorial).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tutorial)); }
//Hàm lưu item public JsonResult CreateItem(string[] price, string[] confidence, int[] x0, int[] y0, int[] x1, int[] y1, object[] target, string[] itemcode) { var code = Session["key"]; FileMain file = db.FileMains.SingleOrDefault(n => n.file_key == code.ToString()); Image img = Image.FromFile(Request.MapPath("~/IMG/img/" + file.file_img)); for (var i = 0; i < price.Length - 1; i++) { var codekey = Guid.NewGuid().ToString(); var pa = Path.Combine(Server.MapPath("~/IMG/Img"), codekey + ".png"); SaveResizeImage(file.file_img, pa, x0[i], y0[i], x1[i], y1[i]); ItemMain itemMain = new ItemMain { item_mvo = price[i], item_pro = float.Parse(confidence[i]), item_datecreate = DateTime.Now, file_id = file.file_id, item_x0 = x0[i], item_y0 = y0[i], item_x1 = x1[i], item_y1 = y1[i], table_id = 1, item_watched = false, notSee = false, item_mvi = price[i], item_img = codekey + ".png", item_target = (string)target[i], item_codeitem = itemcode[i], file_key = file.file_key }; db.ItemMains.Add(itemMain); } db.SaveChanges(); History history2 = new History { file_id = file.file_id, his_title = "đã đọc xong", his_datecreate = DateTime.Now, his_status = 1 }; db.Historys.Add(history2); db.SaveChanges(); return(Json(null)); }
public ActionResult Detail(string id) { Session["key"] = null; FileMain file = db.FileMains.SingleOrDefault(n => n.file_key == id); History history = new History { file_id = file.file_id, his_title = "đã xem", his_datecreate = DateTime.Now, his_status = 1 }; db.Historys.Add(history); db.SaveChanges(); return(View(file)); }
public ActionResult GetNewFileIdforEdit(string FileNo) { //RBACUser rUser = new RBACUser(Session["UserName"].ToString()); //if (!rUser.HasPermission("Group_Edit")) //{ // return Json("D", JsonRequestBehavior.AllowGet); //} try { FileMain FileMainAdd = new FileMain(); var data = _fileMainService.All().ToList().FirstOrDefault(x => x.FileNo == FileNo); if (data != null) { FileMainAdd = data; } return(Json(FileMainAdd, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json("0", JsonRequestBehavior.AllowGet)); } }
public ActionResult SaveNewFile() { HttpFileCollectionBase PhotoFile = Request.Files; var fMain = Request.Form["fMain"]; var obj1 = JObject.Parse(fMain); var FileNo = (string)obj1["fMain"]["FileID"]; try { var fileNoCheck = _fileMainService.All().Where(x => x.FileNo.ToString() == FileNo).Select(x => x.FileNo).FirstOrDefault(); if (fileNoCheck == null) { FileMain FileMainInfo = new FileMain(); FileMainInfo.FileNo = (string)obj1["fMain"]["FileID"]; FileMainInfo.FileSub = (string)obj1["fMain"]["FileSub"]; FileMainInfo.FileRef = (string)obj1["fMain"]["FileRef"]; FileMainInfo.FileText = (string)obj1["fMain"]["FileText"]; FileMainInfo.AttachNum = Convert.ToByte(PhotoFile.Count); //FileMainInfo.FileID = 1; FileMainInfo.UserID = Convert.ToInt32(Session["UserID"].ToString()); //FileMainInfo.VersionNo = _actionListService.All().Select(x=>x.ActDesc).FirstOrDefault(); FileMainInfo.VersionNo = "New"; FileMainInfo.UpdUserID = Convert.ToInt32(Session["UserID"].ToString()); FileMainInfo.CreateDate = DateTime.Now; FileMainInfo.LastUpdDate = DateTime.Now; _fileMainService.Add(FileMainInfo); _fileMainService.Save(); } } catch (Exception ex) { return(Json("0", JsonRequestBehavior.AllowGet)); } //else //{ // return Json("2", JsonRequestBehavior.AllowGet); //} string fileName = ""; string NewPhotoID = ""; string ImgPrefix = ""; string ext = ""; string PhotoPath = ""; string PhysicalPhPath = ""; string DBPhotoPath = ""; try { if (PhotoFile != null) { for (int i = 0; i < PhotoFile.Count; i++) { string fileId = Guid.NewGuid().ToString().Replace("-", ""); HttpPostedFileBase file = PhotoFile[i]; fileName = Path.GetFileName(file.FileName); ext = System.IO.Path.GetExtension(fileName); ImgPrefix = FileNo; //"Photo";//file.ContentType;// int fSize = file.ContentLength; //var path = Path.Combine(Server.MapPath("~/Uploads/Photo/"), MemberCode, fileId); if (ext.ToLower().Contains("txt") || ext.ToLower().Contains("gif") || ext.ToLower().Contains("jpg") || ext.ToLower().Contains("jpeg") || ext.ToLower().Contains("png") || ext.ToLower().Contains(".xls") || ext.ToLower().Contains(".docx") || ext.ToLower().Contains(".xlsx") || ext.ToLower().Contains(".pdf")) { NewPhotoID = ImgPrefix + fileId + ext; PhotoPath = ConfigurationManager.AppSettings["PhotoPath"]; PhysicalPhPath = Path.Combine(Server.MapPath(PhotoPath), NewPhotoID); //var path = Path.Combine(Server.MapPath("~/Images/Photo"), fileName); file.SaveAs(PhysicalPhPath); DBPhotoPath = PhotoPath + "\\" + NewPhotoID; } var NewFile = new FileDetail { AttachFileName = fileName, FileType = ext, Size = fSize, FileSourcePath = PhysicalPhPath, //MainID = (int)obj1["fMain"]["MainID"], MainID = _fileMainService.All().Where(x => x.FileNo == (string)obj1["fMain"]["FileID"]).Select(x => x.MainID).FirstOrDefault(), }; _fileDetailService.Add(NewFile); _fileDetailService.Save(); } } return(Json("1", JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json("0", JsonRequestBehavior.AllowGet)); } }
public ActionResult UpdateFileMain() { HttpFileCollectionBase PhotoFile = Request.Files; var fMain = Request.Form["fMain"]; var obj1 = JObject.Parse(fMain); var FileNo = (string)obj1["fMain"]["FileID"]; var MainID = _fileMainService.All().Where(x => x.FileNo == FileNo).Select(x => x.MainID).FirstOrDefault(); FileMain _FileMainInfo = new FileMain(); _FileMainInfo = _fileMainService.All().ToList().FirstOrDefault(x => x.MainID == MainID); try { if (_FileMainInfo != null) { string fileName = ""; string NewPhotoID = ""; string ImgPrefix = ""; string ext = ""; string PhotoPath = ""; string PhysicalPhPath = ""; string DBPhotoPath = ""; string[] fileList = null; string filesToDelete = ""; if (PhotoFile != null) { if (PhotoFile.Count != 0) { var ExistFD = _fileDetailService.All().ToList().Where(x => x.MainID == MainID); if (ExistFD != null) { foreach (var item in ExistFD) { _fileDetailService.Delete(item); } } } for (int i = 0; i < PhotoFile.Count; i++) { string fileId = Guid.NewGuid().ToString().Replace("-", ""); HttpPostedFileBase file = PhotoFile[i]; fileName = Path.GetFileName(file.FileName); ext = System.IO.Path.GetExtension(fileName); ImgPrefix = FileNo.ToString(); //"Photo";//file.ContentType;// int fSize = file.ContentLength; if (ext.ToLower().Contains("txt") || ext.ToLower().Contains("gif") || ext.ToLower().Contains("jpg") || ext.ToLower().Contains("jpeg") || ext.ToLower().Contains("png") || ext.ToLower().Contains(".xls") || ext.ToLower().Contains(".docx") || ext.ToLower().Contains(".xlsx") || ext.ToLower().Contains(".pdf")) { NewPhotoID = ImgPrefix + fileId + ext; PhotoPath = ConfigurationManager.AppSettings["PhotoPath"]; PhysicalPhPath = Path.Combine(Server.MapPath(PhotoPath), NewPhotoID); filesToDelete = ImgPrefix + "*"; // Only delete files containing "membercode+photo" in their filenames fileList = System.IO.Directory.GetFiles(Server.MapPath(PhotoPath), filesToDelete); foreach (string files in fileList) { System.IO.File.Delete(files); } file.SaveAs(PhysicalPhPath); DBPhotoPath = PhotoPath + "\\" + NewPhotoID; } var NewFile = new FileDetail { AttachFileName = fileName, FileType = ext, Size = fSize, FileSourcePath = PhysicalPhPath, MainID = MainID, }; _fileDetailService.Add(NewFile); _fileDetailService.Save(); } } //FileMain FileMainInfo = new FileMain(); var FileMainUp = _fileMainService.All().Where(x => x.MainID == MainID).FirstOrDefault(); FileMainUp.FileNo = (string)obj1["fMain"]["FileID"]; FileMainUp.FileSub = (string)obj1["fMain"]["FileSub"]; FileMainUp.FileRef = (string)obj1["fMain"]["FileRef"]; FileMainUp.FileText = (string)obj1["fMain"]["FileText"]; FileMainUp.AttachNum = Convert.ToByte(PhotoFile.Count); //FileMainInfo.FileID = 1; FileMainUp.UserID = Convert.ToInt32(Session["UserID"].ToString()); FileMainUp.VersionNo = _actionListService.All().Select(x => x.ActDesc).FirstOrDefault(); FileMainUp.UpdUserID = Convert.ToInt32(Session["UserID"].ToString()); FileMainUp.CreateDate = DateTime.Now; FileMainUp.LastUpdDate = DateTime.Now; _fileMainService.Update(FileMainUp); _fileMainService.Save(); } return(Json("1", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json("0", JsonRequestBehavior.AllowGet)); } }
public void Setvalues(FileMain entity, FileMain existingEntity) { _service.Setvalues(entity, existingEntity); }
public void Delete(FileMain obj) { _service.Delete(obj); }
public void Update(FileMain obj) { _service.Update(obj); }
public void Add(FileMain obj) { _service.Add(obj); }