public async Task <ActionResult> DeleteConfirmed(int id) { OcsbDoc ocsbDoc = await db.OcsbDoc.FindAsync(id); db.OcsbDoc.Remove(ocsbDoc); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "DocID,DocType,DocGroup,DocName,Details,Keyword,FileName,Links,Status")] OcsbDoc ocsbDoc) { if (ModelState.IsValid) { db.Entry(ocsbDoc).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(ocsbDoc)); }
//[Authorize(Roles = "Administrator")] // GET: OcsbDocs/Delete/5 public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OcsbDoc ocsbDoc = await db.OcsbDoc.FindAsync(id); if (ocsbDoc == null) { return(HttpNotFound()); } return(View(ocsbDoc)); }
public async Task <ActionResult> Create(HttpPostedFileBase file, [Bind(Include = "DocID,DocType,DocGroup,DocName,Details,Keyword,FileName,Links,Status")] OcsbDoc ocsbDoc) { if (ModelState.IsValid) { db.OcsbDoc.Add(ocsbDoc); if (file != null && file.ContentLength > 0) { try { string sdate = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString("0000") + "-"; string filename = sdate + file.FileName; //string path = Path.Combine(Server.MapPath("~/Uploads"), Path.GetFileName(file.FileName)); //string url = "http://km.ocsb.go.th/Uploads/" + Path.GetFileName(file.FileName); string path = Path.Combine(Server.MapPath("~/Uploads"), Path.GetFileName(filename)); string url = "http://km.ocsb.go.th/Uploads/" + Path.GetFileName(filename); file.SaveAs(path); ViewBag.Message = "File uploaded successfully"; ocsbDoc.FileName = file.FileName.ToString(); ocsbDoc.Links = url.ToString(); } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } //else //{ // ViewBag.Message = "You have not specified a file."; //} // return View(); //ocsbDoc.Links = path.ToString(); //db.OcsbDoc.Add(ocsbDoc).FileName = file.FileName.ToString(); //db.OcsbDoc.Add(ocsbDoc).Links = path; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(ocsbDoc)); }