コード例 #1
0
ファイル: EditorController.cs プロジェクト: johannegi/CodeFox
 public ActionResult AddFiles(AddFilesViewModel Model)
 {
     // We check if if the user can't open the project.
     if (Pservice.CanUserOpenProject(Model.ProjectID, User.Identity.Name))
     {
         if (ModelState.IsValid)
         {
             // The AddFile(Model) returns a boolean.
             if (!FService.AddFile(Model))
             {
                 // This is the message we send to the Ajax controller,
                 // if the file has the same name, which handles the error message.
                 if (Model.Name == "ReadMe.txt")
                 {
                     return(Json("SameName", JsonRequestBehavior.AllowGet));
                 }
                 return(Json("SameName", JsonRequestBehavior.AllowGet));
             }
             // If succeded we return to Editor
             return(RedirectToAction("Index", new { id = Model.ProjectID }));
         }
         else if (Model.Name == null)
         {
             return(Json("EmptyString", JsonRequestBehavior.AllowGet));
         }
     }
     // If the user can't open the project, or modelstate isn't valid we throw
     // an ArgumentException.
     throw new ArgumentException();
 }
コード例 #2
0
ファイル: EditorController.cs プロジェクト: johannegi/CodeFox
        public ActionResult AddFiles(int ID)
        {
            // We check if if the user can't open the project.
            if (!Pservice.CanUserOpenProject(ID, User.Identity.Name))
            {
                throw new ArgumentException();
            }
            //We initilize the ViewModel and send the partial view.
            AddFilesViewModel Model = new AddFilesViewModel();

            Model.TypeList  = FService.GetTypeList();
            Model.ProjectID = ID;
            // Javascript then puts it into the modal.
            return(PartialView("AddFilesModal", Model));
        }
コード例 #3
0
ファイル: FileService.cs プロジェクト: johannegi/CodeFox
        public bool AddFile(AddFilesViewModel Model)
        {
            var FileWithSameName = DB.FilesInProjects.Where(x => x.ProjectFile.Name == Model.Name &&
                                                            x.FileProject.ID == Model.ProjectID &&
                                                            x.ProjectFile.Type == Model.Type).FirstOrDefault();

            if (FileWithSameName != null)
            {
                return(false);
            }
            // Make the file.
            File NewFile = new File();

            NewFile.Name            = Model.Name;
            NewFile.Type            = Model.Type;
            NewFile.Location        = "//This is a new file";
            NewFile.FolderStructure = null;
            NewFile.DateCreated     = DateTime.Now;
            NewFile.DateModified    = DateTime.Now;

            // Add the connection.
            FileInProject NewConnection = new FileInProject();

            NewConnection.ProjectFile = NewFile;
            Project TheProj = DB.Projects.Where(x => x.ID == Model.ProjectID).FirstOrDefault();

            NewConnection.FileProject = TheProj;

            // Adding to the database.
            DB.Files.Add(NewFile);
            DB.FilesInProjects.Add(NewConnection);
            // If no changes are made to the database we return false.
            if (DB.SaveChanges() == 0)
            {
                return(false);
            }
            return(true);
        }