コード例 #1
0
ファイル: TestController.cs プロジェクト: Rengarmacia/fuelApp
        public async Task <IActionResult> Edit(int id, [Bind("Id,FileName")] Test test)
        {
            if (id != test.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(test);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TestExists(test.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(test));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Fname,Lname,Group,City")] Employee employee)
        {
            if (id != employee.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(employee);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employee.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Car,Emp,Number,Limit")] Card card)
        {
            if (id != card.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(card);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CardExists(card.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(card));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Card,Suma,Km,Km_gps,L,Start,End")] Report report)
        {
            if (id != report.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(report);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReportExists(report.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(report));
        }
コード例 #5
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());
        }
コード例 #6
0
        public async Task <IActionResult> Add(IFormCollection collection)
        {
            // Getting data from the form
            string numberplate = collection["Car.Numberplate"];
            string make        = collection["Car.Make"];
            string model       = collection["Car.Model"];
            string limit       = collection["Card.Limit"];

            string cardnumber  = collection["Card.Number"];
            string cardnumberD = collection["Card.NumberD"];

            string fname  = collection["Employee.Fname"];
            string lname  = collection["Employee.Lname"];
            string city   = collection["Employee.City"];
            string group  = collection["Employee.Group"];
            string emplid = collection["Employee.EmplId"];

            Models.Car newcar = new Models.Car
            {
                NumberPlate = numberplate,
                Make        = make,
                Model       = model
            };
            // If the car already exists, update it
            var fCar = await _kuras_context.Car.FirstOrDefaultAsync(x => x.NumberPlate == newcar.NumberPlate);

            if (fCar != null)
            {
                fCar.UpdateValues(newcar);
                _kuras_context.Update(fCar);
            }
            else
            {
                _kuras_context.Add(newcar);
            }


            Models.Employee newemp = new Models.Employee
            {
                Fname  = fname,
                Lname  = lname,
                City   = city,
                Group  = group,
                EmplId = emplid
            };

            var fEmp = await _kuras_context.Employee.FirstOrDefaultAsync(x => x.EmplId == newemp.EmplId);

            if (fEmp != null)
            {
                fEmp.UpdateValues(newemp);
                _kuras_context.Update(fEmp);
            }
            else
            {
                _kuras_context.Add(newemp);
            }

            await _kuras_context.SaveChangesAsync();

            // Find the newly added or updated employess' and car's IDs
            var newcarId = await _kuras_context.Car.FirstOrDefaultAsync(x => x.NumberPlate == newcar.NumberPlate);

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

            Models.Card newcard = new Models.Card
            {
                Car     = newcarId.Id,
                Emp     = newempId.Id,
                Number  = cardnumber,
                NumberD = cardnumberD,
                Limit   = ((Int32.TryParse(limit, out int limitInt)) ? limitInt : 99)
            };

            _kuras_context.Add(newcard);
            await _kuras_context.SaveChangesAsync();

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