Exemplo n.º 1
0
        public async Task <IActionResult> UploadGps([Bind("Id, gsReport")] kuras.ViewModels.FileUploadViewModel model)
        {
            if (ModelState.IsValid)
            {
                string         webroot = webhostEnvironment.WebRootPath;
                GasStationFile fileObj = Methods.GlobalMethods.UploadFile(model, "kilometers", webroot);
                KilometersFile kmFile  = new KilometersFile
                {
                    FileName = fileObj.FileName,
                    Uploaded = false,
                    Gps      = true
                };
                if (kmFile != null)
                {
                    _context.Add(kmFile);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("ShowGps", new { id = kmFile.Id }));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task <IActionResult> Create([Bind("Id, gsReport")] kuras.ViewModels.FileUploadViewModel model)
        {
            if (ModelState.IsValid)
            {
                string            webroot = webhostEnvironment.WebRootPath;
                GasStationFile    fileObj = Methods.GlobalMethods.UploadFile(model, "remainingfuel", webroot);
                RemainingFuelFile rfObj   = new RemainingFuelFile {
                    FileName = fileObj.FileName,
                    Uploaded = false
                };
                if (rfObj != null)
                {
                    _context.Add(rfObj);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Show", new { id = rfObj.Id }));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id, gsReport")] kuras.ViewModels.FileUploadViewModel upload)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (upload.gsReport != null)
                {
                    string   uploadsFolder = Path.Combine(webhostEnvironment.WebRootPath, "reports");
                    DateTime a             = DateTime.Now;

                    char[] date_now = new char[a.ToString().Length];
                    int    i        = 0;
                    foreach (char b in a.ToString())
                    {
                        if (b == ' ' || b == '/')
                        {
                            date_now[i] = '_';
                        }
                        else if (b == ':')
                        {
                            date_now[i] = ';';
                        }
                        else
                        {
                            date_now[i] = b;
                        }
                        i++;
                    }
                    string temp_string_date = new string(date_now);

                    uniqueFileName = "date-" + temp_string_date + "__" + upload.gsReport.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    upload.gsReport.CopyTo(new FileStream(filePath, FileMode.Create));
                }

                Test test = new Test
                {
                    FileName = uniqueFileName
                };

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

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


            return(View(upload));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Upload([Bind("Id, gsReport")] kuras.ViewModels.FileUploadViewModel model)
        {
            if (ModelState.IsValid)
            {
                string         webroot = webhostEnvironment.WebRootPath;
                GasStationFile fileObj = Methods.GlobalMethods.UploadFile(model, "cards", webroot);
                if (fileObj != null)
                {
                    _context.Add(fileObj);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("ShowFile", new { id = fileObj.Id }));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 5
0
        // Creates a file(from the uploaded) in the specified folder on server
        public static Models.GasStationFile UploadFile(kuras.ViewModels.FileUploadViewModel model, string folderName, string webroot)
        {
            if (model.gsReport != null)
            {
                string uniqueFileName, filePath;
                string uploadsFolder    = Path.Combine(webroot, folderName);
                string temp_string_date = GetDate();

                uniqueFileName = temp_string_date + "__" + model.gsReport.FileName;
                filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                //Create a file
                var fileCreator = new FileStream(filePath, FileMode.Create);
                model.gsReport.CopyTo(fileCreator);
                fileCreator.Close();
                //Put it on the database
                GasStationFile fileObject = new GasStationFile
                {
                    FileName = uniqueFileName,
                    Uploaded = false
                };
                return(fileObject);
            }
            return(null);
        }