public ActionResult SolutionEdit(lu_solution solution,HttpPostedFileBase dosya)
 {
     if (ModelState.IsValid)
     {
         var sol = db.lu_solution.Where(a => a.active == true && a.error_id == solution.ID).FirstOrDefault();
         sol.solutionContent = solution.solutionContent;
         sol.date = solution.date;
         db.SaveChanges();
         if (dosya != null)
         {
             string filename = Guid.NewGuid().ToString();
             int index = dosya.FileName.LastIndexOf(".");
             dosya.SaveAs(Server.MapPath("~/ReportFile/") + filename + dosya.FileName.Substring(index));
             var report = db.tx_report.Where(a => a.active == 1 && a.file_id == sol.ID && a.type == 1).FirstOrDefault();
             if (report != null)
             {
                 string karakter = "/";
                 if (report.reportWay.Contains("\\"))
                     karakter = "\\";
                 string oldfilename = report.reportWay.Substring((1 + report.reportWay.LastIndexOf(karakter)));
                 //if (Directory.Exists(Server.MapPath("~/ReportFile/" + oldfilename)))
                 try
                 {
                     FileInfo f = new FileInfo(Server.MapPath("~/ReportFile/" + oldfilename));
                     f.Delete();
                 }
                 catch { }
                     //Directory.Delete(Server.MapPath("~/ReportFile/" + oldfilename));
                 report.reportName = dosya.FileName;
                 report.reportWay = "../ReportFile/" + filename + dosya.FileName.Substring(index);
                 db.SaveChanges();
             }
             else
             {
                 db.tx_report.AddObject(new tx_report
                 {
                     file_id = solution.ID,
                     reportName = dosya.FileName,
                     reportWay = "../ReportFile/" + filename + dosya.FileName.Substring(index),
                     type = 1,
                     active = 1
                 });
                 db.SaveChanges();
             }
         }
         return RedirectToAction("SolutionEdit", new { ID = sol.error_id, mesaj = 1 });
     }
     return View(solution);
 }
 public ActionResult SolutionCreate(lu_solution sol, int errorID,HttpPostedFileBase dosya)
 {
     if (ModelState.IsValid)
     {
         db.lu_solution.AddObject(new lu_solution
         {
             solutionContent = sol.solutionContent,
             date = sol.date,
             active = true,
             error_id=errorID
         });
         db.SaveChanges();
         if (dosya != null)
         {
             var solution = db.lu_solution.Where(a => a.error_id == errorID && a.active == true).FirstOrDefault();
             if (solution != null)
             {
                 string filename = Guid.NewGuid().ToString() + dosya.FileName.Substring(dosya.FileName.LastIndexOf("."));
                 dosya.SaveAs(Server.MapPath("~/ReportFile/") + filename);
                 db.tx_report.AddObject(new tx_report
                 {
                     file_id = solution.ID,
                     reportName = dosya.FileName,
                     reportWay = "../ReportFile/" + filename,
                     type = 1,
                     active = 1
                 });
                 db.SaveChanges();
             }
         }
         TempData["mesaj"] = "İşlem başarı ile gerçekleşti.";
         return RedirectToAction("SolutionShow", new { ID = errorID, permision = true });
     }
     else
     {
         TempData["mesaj"] = "Bütün bilgileri doldurun...!";
         return RedirectToAction("SolutionCreate", new { ID = errorID, permision = true });
     }
 }
 public ActionResult SolutionCreate(lu_solution solution,HttpPostedFileBase dosya)
 {
     if (ModelState.IsValid)
         {
             var sol = db.lu_solution.Where(a => a.active == true && a.error_id == solution.error_id).ToList();
             if (sol.Count <= 0)
             {
                 db.lu_solution.AddObject(new lu_solution
                 {
                     error_id = solution.error_id,
                     solutionContent = solution.solutionContent,
                     active = true,
                     date = solution.date
                 });
                 db.SaveChanges();
                 var solu = db.lu_solution.Where(a => a.active == true).OrderByDescending(a => a.ID).FirstOrDefault();
                 if (dosya != null)
                 {
                     string filename = Guid.NewGuid().ToString();
                     int index = dosya.FileName.LastIndexOf(".");
                     dosya.SaveAs(Server.MapPath("~/ReportFile/") + filename + dosya.FileName.Substring(index));
                     db.tx_report.AddObject(new tx_report
                     {
                         file_id = solu.ID,
                         reportName = dosya.FileName,
                         reportWay = "../ReportFile/" + filename + dosya.FileName.Substring(index),
                         type = 1,
                         active = 1
                     });
                     db.SaveChanges();
                 }
                 return RedirectToAction("SolutionEdit", new { ID = solution.error_id, mesaj = 1 });
             }
             else
                 return RedirectToAction("SolutionEdit", new { ID = sol.FirstOrDefault().error_id, mesaj = 0 });
         }
     return View(solution);
 }
        public ActionResult SolutionShow(lu_solution sol,int solutionID,int errorID,HttpPostedFileBase dosya)
        {
            if (ModelState.IsValid)
            {
                var solution = db.lu_solution.Where(a => a.ID == solutionID && a.active == true).FirstOrDefault();
                if (solution != null)
                {
                    solution.solutionContent = sol.solutionContent; solution.date = sol.date;
                    db.SaveChanges();
                    if (dosya != null)
                    {
                        string filename = Guid.NewGuid().ToString() + dosya.FileName.Substring(dosya.FileName.LastIndexOf("."));
                        var report = db.tx_report.Where(a => a.active == 1 && a.file_id == solutionID && a.type == 1).FirstOrDefault();
                        if (report != null)
                        {
                            string oldfilename = "";
                            if (report.reportWay.Contains("/"))
                                oldfilename = report.reportWay.Substring(report.reportWay.LastIndexOf("/") + 1);
                            else
                                oldfilename = report.reportWay.Substring(report.reportWay.LastIndexOf("\\") + 1);
                            string denek = Server.MapPath("~/ReportFile/") + oldfilename;
                            try
                            {
                                FileInfo f = new FileInfo(Server.MapPath("~/ReportFile/" + oldfilename));
                                if (f.Exists)
                                    f.Delete();
                            }
                            catch { }

                            dosya.SaveAs(Server.MapPath("~/ReportFile/") + filename);
                            report.reportName = dosya.FileName;
                            report.reportWay = "../ReportFile/" + filename;
                        }
                        else
                        {
                            dosya.SaveAs(Server.MapPath("~/ReportFile/") + filename);
                            db.tx_report.AddObject(new tx_report
                            {
                                file_id = solutionID,
                                reportName = dosya.FileName,
                                reportWay = "../ReportFile/" + filename,
                                type = 1,
                                active = 1
                            });
                        }
                        db.SaveChanges();
                    }
                    TempData["mesaj"] = "İşlem başarı ile gerçekleşti.";
                    return RedirectToAction("SolutionShow", new { ID = errorID, permision = true });
                }
                else
                {
                     return RedirectToAction("SolutionCreate", new { ID = errorID, permision = true });
                }
            }
            else
            {
                TempData["mesaj"] = "Bütün bilgileri doldurun...!";
                return RedirectToAction("SolutionShow", new { ID = errorID, permision = true });
            }
        }