public ActionResult DeleteConfirmed(int id) { tbl_dataFindings tbl_datafindings = db.dataFindings.Find(id); db.dataFindings.Remove(tbl_datafindings); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(tbl_dataFindings tbl_datafindings) { if (ModelState.IsValid) { db.Entry(tbl_datafindings).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_datafindings)); }
public ActionResult Create(tbl_dataFindings tbl_datafindings) { if (ModelState.IsValid) { db.dataFindings.Add(tbl_datafindings); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_datafindings)); }
public ActionResult AddActions(string empno, string actionitemcode, HttpPostedFileBase imagefile, string remarks = "", string requestforreview = "") { string actioncode = get_acode(); string actionimage = ""; ////////////////////// if (imagefile != null) { if (imagefile.ContentLength > 0) { try { tbl_images im = new tbl_images(); string path = System.IO.Path.Combine(Server.MapPath("~/fileImages"), System.IO.Path.GetFileName(imagefile.FileName)); path = Server.MapPath("~/fileImages/" + actionitemcode + "/" + actioncode); if (!Directory.Exists(path)) { DirectoryInfo di = Directory.CreateDirectory(path); } //var im = new tbl_images(); //db.images.Add(im); string ext = System.IO.Path.GetExtension(imagefile.FileName); string newfilename = actioncode; string tosave = path + "/" + newfilename + ext; int i = 0; while (System.IO.File.Exists(tosave)) { i++; newfilename = actioncode + "_" + i; tosave = path + "/" + newfilename + ext; } actionimage = actionitemcode + "/" + actioncode + "/" + newfilename + ext; imagefile.SaveAs(tosave); im = new tbl_images(newfilename, actionimage, actionimage); dbi.images.Add(im); dbi.SaveChanges(); } catch { } } } //////////////// var ac = new tbl_actions(); ac.remarks = remarks; ac.itemcode = actionitemcode; ac.actioncode = actioncode; ac.actionimage = actionimage; ac.p_actioncode = "00000"; ac.empno = empno; db.d_actions.Add(ac); db.SaveChanges(); //check if request for review if (requestforreview == "forreview") { tbl_dataFindings d_item = db.dataFindings.Single(p => p.itemcode == actionitemcode); d_item.status = 2; db.SaveChanges(); } // get gi_code || areaincharge string gicode = db.dataFindings.Where(s => s.itemcode == actionitemcode).Select(s => s.areaincharge).Single(); //get list of incharge var loi = db.emaildept.Where(s => s.gi_code == gicode).ToList(); string[] eset; eset = new string[loi.Count]; if (loi.Count > 0) { int x = 0; foreach (var emp in loi) { try { string email = curuser.users.Single(p => p.empno == emp.empno).email.ToString(); eset[x] = email; x++; } catch (Exception e) { Response.Write(e.Message); } } } // get_emails if (eset.Length > 0) { SendEmail(eset, actionitemcode, remarks); } return(RedirectToAction("Details", new { @id = actionitemcode })); }
public ActionResult NewFindings(tbl_dataFindings tbl_datafindings, IEnumerable <HttpPostedFileBase> files) { if (ModelState.IsValid) { tbl_images im = new tbl_images(); string month = DateTime.Now.ToString("MM"); string year = String.Format("{0:X}", System.Convert.ToInt32(DateTime.Now.ToString("yy"))); string day = DateTime.Now.ToString("dd"); string reccount = db.dataFindings.Count().ToString(); if (System.Convert.ToInt32(reccount) < 10) { reccount = "00" + reccount; } else if (System.Convert.ToInt32(reccount) < 100) { reccount = "0" + reccount; } else if (System.Convert.ToInt32(reccount) >= 1000) { reccount = "0" + reccount; } reccount = reccount.Substring(reccount.Length - 3, 3); string ditemcode = year + month + day + reccount; tbl_datafindings.itemcode = ditemcode; if (files != null) { foreach (HttpPostedFileBase file in files) { if (file != null) { string path = System.IO.Path.Combine(Server.MapPath("~/fileImages"), System.IO.Path.GetFileName(file.FileName)); path = Server.MapPath("~/fileImages/" + ditemcode); if (!Directory.Exists(path)) { DirectoryInfo di = Directory.CreateDirectory(path); DirectoryInfo dthumb = Directory.CreateDirectory(path + "/thumb/"); } string ext = System.IO.Path.GetExtension(file.FileName); string newfilename = ditemcode; string tosave = path + "/" + newfilename + ext; int i = 0; while (System.IO.File.Exists(tosave)) { i++; newfilename = ditemcode + "_" + i; tosave = path + "/" + newfilename + ext; } file.SaveAs(tosave); string thumbdir; thumbdir = path + "/thumb/thumb_" + newfilename + ext; GenerateThumbnails(0.5, file.InputStream, thumbdir); tbl_datafindings.imagePath = ditemcode + "/" + newfilename + ext; im = new tbl_images(ditemcode, ditemcode + "/" + newfilename + ext, ditemcode + "/" + newfilename + ext); dbi.images.Add(im); dbi.SaveChanges(); } } } var department = db.areadept.Where(r => r.areaname == tbl_datafindings.areacode).Single(); tbl_datafindings.areaincharge = department.gi_code; tbl_datafindings.department = department.department; db.dataFindings.Add(tbl_datafindings); db.SaveChanges(); //email Incharge // get gi_code || areaincharge string gicode = department.gi_code; //get list of incharge var loi = db.emaildept.Where(s => s.gi_code == gicode).ToList(); string[] eset; eset = new string[loi.Count]; if (loi.Count > 0) { int x = 0; foreach (var emp in loi) { try { string email = curuser.users.Single(p => p.empno == emp.empno).email.ToString(); eset[x] = email; x++; } catch (Exception e) { Response.Write(e.Message); } } } // get_emails string mailmsg = "<strong>A new finding was found in your Area</strong>"; mailmsg = mailmsg + "<p>Please Click on the Link below to respond with the Finding</p>"; if (eset.Length > 0) { SendEmail(eset, ditemcode, mailmsg, "newFindings"); } ViewBag.Message = "Findings added successfully!"; return(RedirectToAction("Index")); } else { var classification = new SelectList(db.classification.Select(r => r.classification).Distinct().ToList()); ViewBag.classification = classification; var area = new SelectList(db.areadept.Select(r => r.areaname).Distinct().ToList()); ViewBag.areanames = area; ViewBag.Message = "Please Complete required fields"; return(View(tbl_datafindings)); } }
// // GET: /dataFindings/Delete/5 public ActionResult Delete(int id) { tbl_dataFindings tbl_datafindings = db.dataFindings.Find(id); return(View(tbl_datafindings)); }
// // GET: /dataFindings/Details/5 public ViewResult Details(int id) { tbl_dataFindings tbl_datafindings = db.dataFindings.Find(id); return(View(tbl_datafindings)); }