public IActionResult Create(IFormCollection collection)
        {
            string cpuModel           = Request.Form["cpus"].ToString();
            string caseModel          = Request.Form["cases"].ToString();
            string gpuModel           = Request.Form["gpus"].ToString();
            string memoryOptionModel  = Request.Form["memoryoptions"].ToString();
            string motherboardModel   = Request.Form["motherboards"].ToString();
            string storageOptionModel = Request.Form["storageoptions"].ToString();

            decimal price       = decimal.Parse(Request.Form["Price"].ToString());
            string  name        = Request.Form["Name"].ToString();
            string  description = Request.Form["Description"].ToString();
            var     image       = Request.Form.Files.GetFile("image");
            string  imgUrl      = string.Empty;

            if (image != null)
            {
                imgUrl = _driveService.UploadFile(image);
            }
            _service.InsertSystemBuild(cpuModel, caseModel, gpuModel, memoryOptionModel, motherboardModel, storageOptionModel, price, name, description, imgUrl);

            if (ModelState.IsValid)
            {
                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
 public IActionResult Create([Bind("RamId,Model,Manufacturer,MemoryType,MemoryCapacity,MemoryFrequency,Price")] MemoryOption memoryOption)
 {
     if (ModelState.IsValid)
     {
         var image = Request.Form.Files.GetFile("image");
         if (image != null)
         {
             memoryOption.ImgUrl = _driveService.UploadFile(image);
         }
         else
         {
             memoryOption.ImgUrl = Constants.DEFAULT_MEMORY_IMG;
         }
         _service.InsertMemoryOption(memoryOption);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(memoryOption));
 }
Beispiel #3
0
 public IActionResult Create([Bind("Model,Manufacturer,Price,Memory")] Gpu gpu)
 {
     if (ModelState.IsValid)
     {
         var image = Request.Form.Files.GetFile("image");
         if (image != null)
         {
             gpu.ImgUrl = _driveService.UploadFile(image);
         }
         else
         {
             gpu.ImgUrl = Constants.DEFAULT_GPU_IMG;
         }
         _service.InsertGpu(gpu);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(gpu));
 }
Beispiel #4
0
 public IActionResult Create([Bind("MotherboardId,Model,Manufacturer,Price,CpuSocket")] Motherboard motherboard)
 {
     if (ModelState.IsValid)
     {
         var image = Request.Form.Files.GetFile("image");
         if (image != null)
         {
             motherboard.ImgUrl = _driveService.UploadFile(image);
         }
         else
         {
             motherboard.ImgUrl = Constants.DEFAULT_MB_IMG;
         }
         _service.InsertMb(motherboard);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(motherboard));
 }
Beispiel #5
0
 public IActionResult Create([Bind("StorageId,Model,Manufacturer,Price,Type,Capacity")] StorageOption storageOption)
 {
     if (ModelState.IsValid)
     {
         var image = Request.Form.Files.GetFile("image");
         if (image != null)
         {
             storageOption.ImgUrl = _driveService.UploadFile(image);
         }
         else
         {
             storageOption.ImgUrl = Constants.DEFAULT_STORAGE_IMG;
         }
         _service.InsertStorageOption(storageOption);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(storageOption));
 }
Beispiel #6
0
        public IActionResult Create([Bind("CpuId,Model,Price,Manufacturer,Socket,NumberOfCores,CacheMemory")] Cpu cpu)
        {
            if (ModelState.IsValid)
            {
                var image = Request.Form.Files.GetFile("image");
                if (image != null)
                {
                    cpu.ImgUrl = _driveService.UploadFile(image);
                }
                else
                {
                    cpu.ImgUrl = Constants.DEFAULT_CPU_IMG;
                }

                _service.InsertCpu(cpu);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(cpu));
        }
Beispiel #7
0
        public IActionResult Create([Bind("CaseId,Model,Manufacturer,Price,Type")] Case @case)
        {
            if (ModelState.IsValid)
            {
                var image = Request.Form.Files.GetFile("image");
                if (image != null)
                {
                    @case.ImgUrl = _driveService.UploadFile(image);
                }
                else
                {
                    @case.ImgUrl = Constants.DEFAULT_CASE_IMG;
                }

                _service.InsertCase(@case);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(@case));
        }
        public void SyncFolder(SourceFolder sourceFolder, GoogleFolder remoteFolder)
        {
            if (sourceFolder.Files != null)
            {
                foreach (var file in sourceFolder.Files)
                {
                    if (!_googleDriveService.DoesFileExistInFolder(remoteFolder, file.FileName))
                    {
                        try
                        {
                            var remoteFile = _googleDriveService.UploadFile(remoteFolder, file.FileName, file.FullLocation, file.MimeType);
                            _log.Info("File {0} uploaded, google id: {1}", file.FullLocation, remoteFile.Id);
                        }
                        catch (Exception ex)
                        {
                            _log.Error(ex);
                        }
                    }
                    else
                    {
                        _log.Info("File {0} already exists", file.FullLocation);
                    }
                }
            }
            if (sourceFolder.Folders != null)
            {
                foreach (var childFolder in sourceFolder.Folders)
                {
                    if (_googleDriveService.DoesFolderExistInFolder(remoteFolder, childFolder.FolderName))
                    {
                        try
                        {
                            var childRemoteFolder = _googleDriveService.CreateFolder(remoteFolder, childFolder.FolderName);
                            _log.Info("Folder {0} created, google id: {1}", childFolder.FullLocation, childRemoteFolder.Id);

                            SyncFolder(childFolder, childRemoteFolder);
                        }
                        catch (Exception ex)
                        {
                            _log.Error(ex);
                        }
                    }
                    else
                    {
                        _log.Info("Folder {0} already exists", childFolder.FullLocation);
                    }
                }
            }
        }
        public async Task <SyncedFileInfo> SendFile(Stream stream, string[] pathParts, SyncTarget target, IProgress <double> progress, CancellationToken cancellationToken)
        {
            _logger.Debug("Sending file {0} to {1}", string.Join("/", pathParts), target.Name);

            var syncAccount = _configurationRetriever.GetSyncAccount(target.Id);

            var googleCredentials = GetGoogleCredentials(target);

            var file = await _googleDriveService.UploadFile(stream, pathParts, syncAccount.FolderId, googleCredentials, progress, cancellationToken);

            return(new SyncedFileInfo
            {
                Path = file.Item2,
                Protocol = MediaProtocol.Http,
                Id = file.Item1
            });
        }
Beispiel #10
0
        public ActionResult UploadFile()
        {
            var data = _googleDriveService.UploadFile();

            return(JsonResult(data, true));
        }