Ejemplo n.º 1
0
        public ActionResult getMessage(int projectID, string message)
        {
            System.Diagnostics.Debug.WriteLine(projectID + "PID");
            ViewBag.DashboardText = "Further Requirements";
            user active = TempData["ActiveUser"] as user;

            if (active == null)
            {
                return(RedirectToAction("SignIn", "Home"));
            }
            else
            {
                TempData["ActiveUser"] = active;
                if (active.staffPosition != "RIS")
                {
                    return(RedirectToAction("ControllerChange", "Home"));
                }
            }
            var db            = new Entities();
            var projectToEdit = db.projects.Where(p => p.projectID == projectID).First();

            System.Diagnostics.Debug.WriteLine(projectToEdit.projectID + "PID2");
            System.Diagnostics.Debug.WriteLine(projectToEdit.projectStage + "projectStage");
            if ((active.staffPosition == "RIS" && projectToEdit.projectStage == "Awaiting Further Information"))
            {
                // update database
                db.Set <project>().Attach(projectToEdit);
                db.Entry(projectToEdit).State = System.Data.Entity.EntityState.Modified;
                SharedControllerMethods.addToHistory(active.userID, projectID, message);
                db.SaveChanges();

                TempData["alert"] = "You have returned " + projectToEdit.pName + " for further information";
            }
            else if ((active.staffPosition == "RIS" && projectToEdit.projectStage == "Awaiting Clarification"))
            {
                // update database
                db.Set <project>().Attach(projectToEdit);
                db.Entry(projectToEdit).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                HelperClasses.SharedControllerMethods.addToHistory(active.userID, projectID, message);
            }
            else if ((active.staffPosition == "RIS" && projectToEdit.projectStage == "Awaiting Corrections"))
            {
                // update signatures based on current user
                projectToEdit.projectStage = "Awaiting Corrections";

                // update database
                db.Set <project>().Attach(projectToEdit);
                db.Entry(projectToEdit).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                HelperClasses.SharedControllerMethods.addToHistory(active.userID, projectID, message);
            }
            else
            {
                TempData["alert"] = "You do not have permission to request further information for : " + projectToEdit.pName;
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult ReuploadExpend(int projectID, HttpPostedFileBase file) // -
        {
            //TempData Check and Renewal
            user active = TempData["ActiveUser"] as user;

            if (active == null)
            {
                return(RedirectToAction("SignIn", "Home"));
            }
            else
            {
                TempData["ActiveUser"] = active;
                if (active.staffPosition != "RIS")
                {
                    return(RedirectToAction("ControllerChange", "Home"));
                }
            }

            var allowedExtensions = new[] { ".xls", ".xlsx" };

            if (!allowedExtensions.Contains(Path.GetExtension(file.FileName)))
            {
                TempData["alert"] = "Select a file with extension type: " + string.Join(" ", allowedExtensions);
                return(RedirectToAction("Index"));
            }
            var path = "";

            try
            {
                if (file.ContentLength > 0)
                {
                    System.Diagnostics.Debug.WriteLine("filelength > 0");
                    var    fileName      = Path.GetFileName(file.FileName);
                    var    fileextension = Path.GetExtension(fileName);
                    Random rand          = new Random();
                    do
                    {
                        fileName = rand.Next(1, 10000000).ToString();
                        String TestName = fileName + fileextension;
                        path = Path.Combine(Server.MapPath("~/App_Data/ExpenditureFiles"), TestName);
                    } while (System.IO.File.Exists(path) == true);

                    file.SaveAs(path);
                }
            }
            catch
            {
                ViewBag.Message = "Upload failed";
                return(RedirectToAction("Index"));
            }

            Entities db            = new Entities();
            var      sampleProject = db.projects.Where(p => p.projectID == projectID).First();
            var      fToDel        = sampleProject.projectFile;

            sampleProject.projectFile = path;
            db.Set <project>().Attach(sampleProject);
            db.Entry(sampleProject).State = System.Data.Entity.EntityState.Modified;

            db.SaveChanges();
            SharedControllerMethods.addToHistory(active.userID, projectID, "Modified the project file");
            if (System.IO.File.Exists(fToDel))
            {
                System.IO.File.Delete(fToDel);
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult EditProject(project edited, HttpPostedFileBase file)
        {
            user active = TempData["ActiveUser"] as user;

            if (active == null)
            {
                return(RedirectToAction("SignIn", "Home"));
            }
            else
            {
                TempData["ActiveUser"] = active;

                if (active.staffPosition != "Researcher")
                {
                    return(RedirectToAction("ControllerChange", "Home"));
                }
            }

            Entities db            = new Entities();
            var      sampleProject = db.projects.Where(p => p.projectID == edited.projectID).First();

            sampleProject.pName        = edited.pName;
            sampleProject.pDesc        = edited.pDesc;
            sampleProject.projectStage = "Created";
            sampleProject.pAbstract    = edited.pAbstract;
            var allowedExtensions = new[] { ".xls", ".xlsx" };

            if (!allowedExtensions.Contains(Path.GetExtension(file.FileName)))
            {
                TempData["alert"] = "Select a file with extension type: " + string.Join(" ", allowedExtensions);;
                return(RedirectToAction("createProject"));
            }
            var path = "";

            try
            {
                if (file.ContentLength > 0)
                {
                    System.Diagnostics.Debug.WriteLine(": COntent>0");
                    var fileName      = Path.GetFileName(file.FileName);
                    var fileextension = Path.GetExtension(fileName);;

                    do
                    {
                        System.Diagnostics.Debug.WriteLine("Do");
                        const int STRING_LENGTH = 32;
                        fileName = Crypto.GenerateSalt(STRING_LENGTH).Substring(0, STRING_LENGTH);
                        String TestName = fileName + fileextension;
                        path = Path.Combine(Server.MapPath("~/App_Data/ExpenditureFiles"), TestName);
                    } while (System.IO.File.Exists(path) == true);

                    System.Diagnostics.Debug.WriteLine(path + "path");
                    file.SaveAs(path);
                }
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("Catch");
                TempData["alert"] = "Error Uploading";
                return(RedirectToAction("Index"));
            }
            db.Set <project>().Attach(sampleProject);
            db.Entry(sampleProject).State = System.Data.Entity.EntityState.Modified;
            SharedControllerMethods.addToHistory(active.userID, edited.projectID, "Changed Project Details");
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult CreateProject(project model, HttpPostedFileBase file)
        {
            //TempData Check and Renewal
            user active = TempData["ActiveUser"] as user;

            if (active == null)
            {
                return(RedirectToAction("SignIn", "Home"));
            }
            else
            {
                TempData["ActiveUser"] = active;
                if (active.staffPosition != "Researcher")
                {
                    return(RedirectToAction("ControllerChange", "Home"));
                }
            }
            System.Diagnostics.Debug.WriteLine(active.staffPosition + " : staffPos");
            var allowedExtensions = new[] { ".xls", ".xlsx" };

            if (!allowedExtensions.Contains(Path.GetExtension(file.FileName)))
            {
                TempData["alert"] = "Select a file with extension type: " + string.Join(" ", allowedExtensions);;
                return(RedirectToAction("createProject"));
            }
            var path = "";

            try
            {
                if (file.ContentLength > 0)
                {
                    System.Diagnostics.Debug.WriteLine(": COntent>0");
                    var    fileName      = Path.GetFileName(file.FileName);
                    var    fileextension = Path.GetExtension(fileName);;
                    Random rand          = new Random();
                    do
                    {
                        System.Diagnostics.Debug.WriteLine("Do");
                        fileName = rand.Next(1, 10000000).ToString();
                        String TestName = fileName + fileextension;
                        path = Path.Combine(Server.MapPath("~/App_Data/ExpenditureFiles"), TestName);
                    } while (System.IO.File.Exists(path) == true);

                    System.Diagnostics.Debug.WriteLine(path + "path");
                    file.SaveAs(path);
                }
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("Catch");
                TempData["alert"] = "Error Uploading";
                return(RedirectToAction("CreateProject"));
            }

            if (ModelState.IsValid)
            {
                var db = new Entities();

                project tempProject = new project
                {
                    userID       = active.userID,
                    dateCreated  = DateTime.Now.ToUniversalTime(),
                    projectStage = "Created",
                    pName        = model.pName,
                    pAbstract    = model.pAbstract,
                    pDesc        = model.pDesc,
                    projectFile  = path,
                };
                project addedProject = db.projects.Add(tempProject);
                db.SaveChanges();
                SharedControllerMethods.addToHistory(active.userID, addedProject.projectID, "Created Project");
                ViewBag.Message = "Created Project";
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }