public async Task <IActionResult> Create([Bind("BusId,Name,Age")] Buses buses)
        {
            if (ModelState.IsValid)
            {
                _context.Add(buses);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(buses));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("TypeId,TypeName,Description")] Models.Type @type)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@type);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@type));
        }
        public async Task <IActionResult> Create([Bind("PriceId,BusId,TypeId,Cost")] Price price)
        {
            if (ModelState.IsValid)
            {
                _context.Add(price);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BusId"]  = new SelectList(_context.Buses, "BusId", "BusId", price.BusId);
            ViewData["TypeId"] = new SelectList(_context.Type, "TypeId", "TypeId", price.TypeId);
            return(View(price));
        }
示例#4
0
        public override Task <Response> AddBus(Bus request, ServerCallContext context)
        {
            Response response = new Response();

            try
            {
                var optionsBuilder = new DbContextOptionsBuilder <BusContext>();
                optionsBuilder.UseSqlite("Data sourse = tdb.mdf");
                using var con = new BusContext(optionsBuilder.Options);
                con.Buses.Add(request);
                con.SaveChangesAsync();
            }
            catch (Exception e)
            {
                _logger.LogInformation(e.Message);
                response.ModificationResponse = Changes.AddFailed;
                return(Task.FromResult(response));
            }
            response.ModificationResponse = Changes.AddOk;
            return(Task.FromResult(response));
        }