//public ActionResult NewCase() //{ // unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"]; // GenericRepository<Priority> priority_caseRepository = unitOfWork.GetRepoInstance<Priority>(); // //GenericRepository<Status> status_caseRepository = unitOfWork.GetRepoInstance<Status>(); // GenericRepository<Category> category_caseRepository = unitOfWork.GetRepoInstance<Category>(); // List<Priority> priorities = priority_caseRepository.GetAll().ToList(); // List<Category> categories = category_caseRepository.GetAll().ToList(); // ViewBag.Priorities = priorities; // ViewBag.Categories = categories; // NewCaseVM newcasevm = new NewCaseVM(); // newcasevm.Case = new Case(); // newcasevm.CaseID = newcasevm.Case.CaseID; // return View(newcasevm); //} //Submit New Case public ActionResult SendCase(NewCaseVM newCase) { long userId; if (Session["USER"] != null) { userId = ((User)Session["USER"]).UserID; } else { userId = 1; } unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"]; GenericRepository <Case> caserepo = unitOfWork.GetRepoInstance <Case>(); GenericRepository <DAL.File> filerepo = unitOfWork.GetRepoInstance <DAL.File>(); Case startupCase = new Case(); startupCase = newCase.Case; startupCase.SubmissionDate = DateTime.Now; startupCase.StatusID = 4; startupCase.StartupID = userId; caserepo.Add(startupCase); //try //{ if (newCase.File != null) { Guid g = Guid.NewGuid(); string GuidString = Convert.ToBase64String(g.ToByteArray()); GuidString = GuidString.Replace("=", ""); GuidString = GuidString.Replace("+", ""); string _FileName = Path.GetFileName(newCase.File.FileName); string _UniqueFileName = GuidString + "+" + _FileName; //string _path = Path.Combine(Server.MapPath("~/UploadedFiles"), _UniqueFileName); byte[] uploadedFile = new byte[newCase.File.InputStream.Length]; //var x = newCase.File.InputStream.Read(uploadedFile, 0, uploadedFile.Length); DAL.File NewFile = new DAL.File(); NewFile.FileName = _FileName; NewFile.SavedFileName = _UniqueFileName; NewFile.CaseID = startupCase.CaseID; NewFile.Content = uploadedFile; NewFile.FileType = newCase.File.ContentType; filerepo.Add(NewFile); } //} //catch //{ // ViewBag.Message = "File upload failed!!"; // return View("NewCase", newCase); //} unitOfWork.SaveChanges(); return(RedirectToAction("Dashboard")); }
private List <DAL.File> getFiles(string path) { var files = new DirectoryInfo(path).GetFiles(); List <DAL.File> list = new List <DAL.File>(); foreach (var file in files) { DAL.File newFile = new DAL.File(); newFile.name = file.Name; newFile.size = file.Length; newFile.id = 0; newFile.allUsers = config.name; list.Add(newFile); } return(list); }