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,Card,Suma,Km,Km_gps,L,Start,End")] Report report)
        {
            if (ModelState.IsValid)
            {
                _context.Add(report);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(report));
        }
        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());
            }
        }
        public async Task <IActionResult> Create([Bind("Id,Fname,Lname,Group,City")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
Beispiel #5
0
        public async Task <IActionResult> Create([Bind("Id,Make,Model,NumberPlate")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
Beispiel #6
0
        // INSERT DATA
        // GET: GasStation/Insert/5
        public async Task <IActionResult> Insert(int?id)
        {
            //if no such id
            if (id == null)
            {
                return(NotFound());
            }

            var gasStationFile = await _context.GasStationFile
                                 .FirstOrDefaultAsync(m => m.Id == id);

            //if no data in that id
            if (gasStationFile == null)
            {
                return(NotFound());
            }

            if (gasStationFile.FileName != null)
            {
                //returns
                var Data = GasStationReport(gasStationFile.FileName);
                if (Data.Any())
                {
                    foreach (var el in Data)
                    {
                        _context.Add(el);
                    }
                    gasStationFile.Uploaded = true;
                    _context.Update(gasStationFile);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(NotFound());
                }
            }
            return(View());
        }
        // Hidden function, not available via button
        // Adds all Axapta table records to Car, Card and Employee tables
        public async Task <IActionResult> AddAll()
        {
            var axaptaData = await _kuras_context.Axapta.ToListAsync();

            var addViewModel = new AxaptaViewModels.AddViewModel();

            foreach (var el in axaptaData)
            {
                addViewModel = await GenerateAddViewModel(el);

                if (addViewModel != null)
                {
                    // !!!Check if the car exists
                    _kuras_context.Add(addViewModel.Car);
                    // There can be an employee that drives more than one car
                    if (await _kuras_context.Employee.FirstOrDefaultAsync(x => x.Id == addViewModel.Employee.Id) == null)
                    {
                        _kuras_context.Add(addViewModel.Employee);
                    }
                    // Saving changes to retrieve ids from tables
                    await _kuras_context.SaveChangesAsync();

                    var newcarId = await _kuras_context.Car.FirstOrDefaultAsync(x => x.NumberPlate == addViewModel.Car.NumberPlate);

                    var newempId = await _kuras_context.Employee.FirstOrDefaultAsync(x => x.EmplId == addViewModel.Employee.EmplId);

                    addViewModel.Card.Car = newcarId.Id;
                    addViewModel.Card.Emp = newempId.Id;

                    _kuras_context.Add(addViewModel.Card);
                    await _kuras_context.SaveChangesAsync();
                }
            }
            // removes all records from axapta table
            DeleteTable();
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #8
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));
        }
Beispiel #9
0
        public async Task <IActionResult> Create([Bind("Id,Car,Emp,Number,Limit")] Card card)
        {
            if (ModelState.IsValid)
            {
                _context.Add(card);
                await _context.SaveChangesAsync();

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