Esempio n. 1
0
        public async Task <IActionResult> Create(CreateFileViewModel createFilevm)
        {
            if (ModelState.IsValid)
            {
                File newFile = new File
                {
                    ConsumerID    = createFilevm.ConsumerID,
                    CaseManagerID = createFilevm.CaseManagerID,
                    RoomID        = createFilevm.RoomID,
                    Quantity      = createFilevm.Quantity
                };

                //if file already exists, ask if user would like to update quantity
                if (_context.FileExists(newFile))
                {
                    File oldFile = _context.Files.First(f => f.CaseManagerID == newFile.CaseManagerID && f.ConsumerID == newFile.ConsumerID && f.RoomID == newFile.RoomID);

                    return(Redirect(String.Format("AddConfirm?id={0}&userNum={1}", oldFile.ID, newFile.Quantity)));
                }
                ;

                _context.Add(newFile);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(createFilevm));
        }
Esempio n. 2
0
        // GET: Files/Create
        public IActionResult Create(int?id)
        {
            //Check if user logged in:
            if (HttpContext.Session.GetString("Username") == null)
            {
                return(Redirect("/Home/Login"));
            }

            // Make ViewModel
            CreateFileViewModel createFileVM = new CreateFileViewModel
            {
                CaseManagers = _context.CaseManagers.Select(cm => new SelectListItem()
                {
                    Value = cm.ID.ToString(), Text = cm.FullName()
                }).ToList(),
                Consumers = _context.Consumers.Select(c => new SelectListItem()
                {
                    Value = c.ID.ToString(), Text = c.FullName()
                }).ToList(),
                Rooms = _context.Rooms.Select(r => new SelectListItem()
                {
                    Value = r.ID.ToString(), Text = r.Name
                }).ToList()
            };

            // Add Consumer name if id was passed in
            if (id != null)
            {
                createFileVM.ConsumerID = (int)id;
            }

            return(View(createFileVM));
        }
Esempio n. 3
0
        public CreateFileWindow()
        {
            InitializeComponent();

            WindowStyle = WindowStyle.None;

            m_ViewModel = new CreateFileViewModel(this);
            Model       = m_ViewModel.Model;
            DataContext = Model;
        }
Esempio n. 4
0
        // Returns true if the file is in the project that gets sent in by the CreateFileViewModel
        public bool FileExistsInProject(CreateFileViewModel newFile)
        {
            var file = (from f in _db.Files
                        where f.Name == newFile.Name &&
                        f.ProjectID == newFile.ProjectID &&
                        f.Type == newFile.Type
                        select f).SingleOrDefault();

            return(file != null);
        }
Esempio n. 5
0
        public static async Task <bool> Upload(CreateFileViewModel model, FileGroups fileGroup, Controller controller)
        {
            try
            {
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    var guid        = Guid.NewGuid();
                    var fileExt     = System.IO.Path.GetExtension(model.File.FileName);
                    var newFileName = guid.ToString();

                    var newFile = new File
                    {
                        Id           = newFileName,
                        Name         = model.Name,
                        Description  = model.Description,
                        Extension    = fileExt,
                        Size         = model.File.ContentLength,
                        CreateUserId = controller.User.Identity.GetUserId(),
                        CreateTime   = DateTime.Now,
                    };
                    var destinationFolder = "";

                    var categoryG = await db.Categories.FindAsync((int)fileGroup);

                    newFile.Categories.Add(categoryG);

                    if (fileExt == ".png" || fileExt == ".jpg")
                    {
                        var categoryT = await db.Categories.FindAsync((int)FileTypes.Image);

                        newFile.Categories.Add(categoryT);
                        destinationFolder = Properties.Resources.UploadFolder_Image;
                    }
                    else
                    {
                        var categoryT = await db.Categories.FindAsync((int)FileTypes.Other);

                        newFile.Categories.Add(categoryT);
                        destinationFolder = Properties.Resources.UploadFolder_Other;
                    }

                    db.Files.Add(newFile);
                    await db.SaveChangesAsync();

                    var newPath = System.IO.Path.Combine(controller.Server.MapPath("~/" + destinationFolder), newFileName + fileExt);
                    model.File.SaveAs(newPath);
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 6
0
        public async Task <ActionResult> Create(CreateFileViewModel model)
        {
            if (ModelState.IsValid)
            {
                var uploadResult = await Uploader.Upload(model, FileGroups.Other, this);

                if (uploadResult)
                {
                    return(RedirectToAction("List"));
                }
            }
            return(View(model));
        }
Esempio n. 7
0
        // Creates a pop up window for create file and takes in project id
        public ActionResult CreateFile(int id)
        {
            string userId = User.Identity.GetUserId();

            if (pservice.AuthorizeProject(userId, id))
            {
                var viewModel = new CreateFileViewModel();
                viewModel.ProjectID = id;
                return(View(viewModel));
            }

            return(View("Error"));
        }
Esempio n. 8
0
        // Creates a file with the attributes from the CreateFileViewModel
        public void CreateFile(CreateFileViewModel fileVM)
        {
            File file = new File
            {
                Name      = fileVM.Name,
                Type      = fileVM.Type,
                Content   = "",
                ProjectID = fileVM.ProjectID
            };

            _db.Files.Add(file);
            _db.SaveChanges();
        }
Esempio n. 9
0
        public ActionResult CreateFile(CreateFileViewModel file)
        {
            if (pservice.FileExistsInProject(file))
            {
                ModelState.AddModelError("Name", "There is already a file by that name.");
            }

            if (!ModelState.IsValid)
            {
                return(View(file));
            }

            pservice.CreateFile(file);
            return(RedirectToAction("ViewProject", new { id = file.ProjectID }));
        }
Esempio n. 10
0
        public void TestCreateFile()
        {
            int projectId = 1;
            var fileVM    = new CreateFileViewModel
            {
                Name      = "newfile",
                Type      = "js",
                ProjectID = projectId
            };

            pservice.CreateFile(fileVM);

            var result = pservice.GetProject(projectId).Files;

            Assert.AreEqual(3, result.Count);
        }
Esempio n. 11
0
 public CreateFileView(CreateFileViewModel viewModel)
 {
     InitializeComponent();
     DataContext = ViewModel = viewModel;
     ViewModel.SelectEncoding(ViewModel.MainViewModel.PluginsStudioController.PluginsController.ConfigurationController.LastEncodingIndex);
     ViewModel.Close += (sender, eventArgs) =>
     {
         // Guarda la codificación
         if (eventArgs.IsAccepted)
         {
             ViewModel.MainViewModel.PluginsStudioController.PluginsController.ConfigurationController.LastEncodingIndex = (int)ViewModel.GetSelectedEncoding();
             ViewModel.MainViewModel.PluginsStudioController.PluginsController.ConfigurationController.Save();
         }
         DialogResult = eventArgs.IsAccepted;
         Close();
     };
 }
Esempio n. 12
0
        public ActionResult CreateFile(CreateFileViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("ErrorsList", ProceedModelState()));
            }

            try
            {
                FoldersService.CreateFile(viewModel.Path, viewModel.Name);
            }
            catch (Exception exception)
            {
                return(PartialView("ErrorsList", ProcessException(exception)));
            }

            return(GetFolderView(viewModel.Path));
        }
Esempio n. 13
0
        // Creates a project with the attributes from the CreateProjectViewModel that gets sent in
        public void CreateProject(CreateProjectViewModel projectVM)
        {
            Project project = new Project
            {
                Name    = projectVM.Name,
                Type    = projectVM.Type,
                OwnerID = projectVM.OwnerID,
            };

            _db.Projects.Add(project);
            _db.SaveChanges();

            CreateFileViewModel file = new CreateFileViewModel
            {
                Name      = "index",
                Type      = project.Type,
                ProjectID = project.ID
            };

            CreateFile(file);
        }
Esempio n. 14
0
        public async Task <IActionResult> Create([FromForm] CreateFileViewModel viewModel)
        {
            var createFiles = Create(viewModel.Files);

            var results = await Task.WhenAll(createFiles);

            var result = Result.Combine(results);

            if (result.Failure)
            {
                TempData["Failure"] = result.Message;

                _uow.Rollback();

                return(RedirectToAction("Index", "Product"));
            }

            TempData["Success"] = "File has been created";

            _uow.Commit();

            return(RedirectToAction("Index", "Product"));
        }
Esempio n. 15
0
        public void TestFileExistsInProject()
        {
            var fileVM1 = new CreateFileViewModel
            {
                Name      = "file4",
                ProjectID = 1,
                Type      = "js"
            };
            var fileVM2 = new CreateFileViewModel
            {
                Name      = "file4",
                ProjectID = 1,
                Type      = "html"
            };
            var fileVM3 = new CreateFileViewModel
            {
                Name      = "file4",
                ProjectID = 2,
                Type      = "js"
            };
            var fileVM4 = new CreateFileViewModel
            {
                Name      = "index",
                ProjectID = 2,
                Type      = "cs"
            };

            var result1 = pservice.FileExistsInProject(fileVM1);
            var result2 = pservice.FileExistsInProject(fileVM2);
            var result3 = pservice.FileExistsInProject(fileVM3);
            var result4 = pservice.FileExistsInProject(fileVM4);

            Assert.IsTrue(result1);
            Assert.IsFalse(result2);
            Assert.IsFalse(result3);
            Assert.IsTrue(result4);
        }
Esempio n. 16
0
        public ActionResult CreateFile(CreateFileViewModel fileModel)
        {
            List <ExplorerViewModel> explorerObjects;

            if (fileModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            string path = fileModel.ParentDirectoryPath + fileModel.Name + "." + fileModel.Extension;

            if (fileService.IsExist(path))
            {
                return(Json(new { Status = "Exist" }, JsonRequestBehavior.AllowGet));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    fileService.CreateFile(path);

                    var dirListModel =
                        directoryService.GetAllDirectories(fileModel.ParentDirectoryPath).Select(d => d.ToExplorerObject());
                    var fileListModel = fileService.GetAllFiles(fileModel.ParentDirectoryPath).Select(f => f.ToExplorerObject());

                    explorerObjects = new List <ExplorerViewModel>();

                    foreach (var obj in dirListModel)
                    {
                        explorerObjects.Add(obj);
                    }

                    foreach (var obj in fileListModel)
                    {
                        explorerObjects.Add(obj);
                    }
                }
                catch (UnauthorizedAccessException e)
                {
                    return(Json(new { Status = "NotAcceptable" }, JsonRequestBehavior.AllowGet));
                }

                path = fileModel.ParentDirectoryPath.Remove(1, 1);

                if (path.Last() != '\\')
                {
                    path = path + "\\";
                }
                path = path.Replace("\\", "\\\\");

                ViewBag.LastPath = path;
                return(PartialView("GetExplorerTable", explorerObjects));
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView(fileModel));
            }
            return(View(fileModel));
        }