Exemple #1
0
 public static void createArtifact(Artifact artifact, string username)
 {
     CTContext db = new CTContext();
     artifact.User = db.Users.FirstOrDefault(u => u.UserName == username);
     db.Artifacts.Add(artifact);
     db.SaveChanges();
 }
Exemple #2
0
 public ArtifactView(Artifact g)
 {
     CategoriesList = new Dictionary<string, bool>();
     this.ArtifactObj = g;
     List<Category> currCats = g.Categories.ToList();
     foreach (Category cat in new CTContext().Categories.ToList()) {
         CategoriesList[cat.Name] = (currCats.Contains(cat));
     }
 }
        public ActionResult Create(Artifact artifact, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {

                if (file != null && file.ContentLength > 0)
                {
                    try
                    {
                        //string usr = User.Identity.Name.ToString();
                        //string test = Path.GetFileNameWithoutExtension(file.FileName);
                        var dirPath = Server.MapPath("/Artifacts/" + User.Identity.Name + "/");
                        Directory.CreateDirectory(dirPath);
                        //var fileName = test + "-" + usr + System.IO.Path.GetExtension(file.FileName);
                        string path = Path.Combine(dirPath, file.FileName);
                        if ((System.IO.Path.GetExtension(file.FileName)).ToString().Equals(".exe") || (System.IO.Path.GetExtension(file.FileName)).ToString().Equals(".bat"))
                        {
                            Response.Write(@"<script language='javascript'>alert('Please do not upload .exe or .bat files.');</script>");
                            throw new InvalidDataException("bat and exe files can't be uploaded.");
                        }
                        if(System.IO.File.Exists(path))
                        {
                            Response.Write(@"<script language='javascript'>alert('A file with that name has already been uploaded by you. Please update your artifact through the edit link, if you wish to update your file.');</script>");
                            throw new Exception("File already uploaded");
                        }
                        file.SaveAs(path);
                        artifact.Location = file.FileName;
                        ArtifactRepo.createArtifact(artifact, User.Identity.Name.ToString());
                        return RedirectToAction("Index");
                        //ViewBag.Message = "File uploaded successfully";
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = "ERROR:" + ex.Message.ToString();
                    }
                }
            }
            return View(artifact);
        }
        public ActionResult Edit(Artifact artifact, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                FileDeletion(Session["location"].ToString());
                Session["location"] = null;
                //artifact.Location = file.FileName;
                //db.Entry(artifact).State = EntityState.Modified;
                //db.SaveChanges();
                if (file != null && file.ContentLength > 0)
                {
                    try
                    {
                        //string usr = User.Identity.Name.ToString();
                        //string test = Path.GetFileNameWithoutExtension(file.FileName);
                        var dirPath = Server.MapPath("/Artifacts/" + User.Identity.Name + "/");
                        Directory.CreateDirectory(dirPath);
                        //var fileName = test + "-" + usr + System.IO.Path.GetExtension(file.FileName);
                        string path = Path.Combine(dirPath, file.FileName);
                        if ((System.IO.Path.GetExtension(file.FileName)).ToString().Equals(".exe") || (System.IO.Path.GetExtension(file.FileName)).ToString().Equals(".bat"))
                        {
                            Response.Write(@"<script language='javascript'>alert('Please do not upload .exe or .bat files.');</script>");
                            throw new InvalidDataException("bat and exe files can't be uploaded.");
                        }
                        file.SaveAs(path);
                        artifact.Location = file.FileName;
                        //ArtifactRepo.createArtifact(artifact, User.Identity.Name.ToString());
                        return RedirectToAction("Index");
                        //ViewBag.Message = "File uploaded successfully";
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = "ERROR:" + ex.Message.ToString();
                    }
                }

                db.Entry(artifact).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(artifact);
        }
Exemple #5
0
        /**
         * Checks whether the given user, identified by the usr string parameter,
         * has the requested type of access to the given artifact.
         *
         * Parameters:
         *  art         : The artifact in question
         *  usr         : The username of the user requesting access
         *  accessType  : whether write/delete access is being requested.
         **/
        public static bool checkArtifactPermissions(Artifact art, string usr, bool accessType)
        {
            bool returnValue = false;

            return returnValue;
        }