Пример #1
0
        static void InsertCarTechState(string comment, CarServiceContext context)
        {
            var rand = new Random();

            int firstInspectorId = context.Inspectors.First().InspectorId;
            int firstCarId       = context.Cars.First().CarId;

            int lastInspectorId = context.Inspectors.Last().InspectorId;
            int lastCarId       = context.Cars.Last().CarId;

            var state = new CarTechState
            {
                CarId       = rand.Next(firstCarId, lastCarId + 1),
                InspectorId = rand.Next(firstInspectorId, lastInspectorId + 1),
                Date        = new DateTime(rand.Next(2000, DateTime.Now.Year + 1), rand.Next(1, 13), rand.Next(1, 29)),
                Mileage     = rand.NextDouble() * 1000.0,
                BrakeSystem = "Тормозная_система_" + rand.Next(1, 6),
                Suspension  = "Подвеска_" + rand.Next(1, 6),
                Wheels      = "Колёса_" + rand.Next(1, 6),
                Lightning   = "Осветительный_прибор_" + rand.Next(1, 6),
                MarkOnPassageOfServiceStation = rand.NextBool()
            };

            Insert(comment, "Car tech state", state, context);
        }
        public IActionResult Put([FromBody] CarTechState state)
        {
            if (state == null)
            {
                return(BadRequest());
            }

            var fromDb = _context.CarTechStates.FirstOrDefault(s => s.CarTechStateId == state.CarTechStateId);

            if (fromDb == null)
            {
                return(NotFound());
            }

            fromDb.CarId                         = state.CarId;
            fromDb.InspectorId                   = state.InspectorId;
            fromDb.Date                          = state.Date;
            fromDb.Mileage                       = state.Mileage;
            fromDb.BrakeSystem                   = state.BrakeSystem;
            fromDb.Suspension                    = state.Suspension;
            fromDb.Wheels                        = state.Wheels;
            fromDb.Lightning                     = state.Lightning;
            fromDb.AdditionalEquipment           = state.AdditionalEquipment;
            fromDb.MarkOnPassageOfServiceStation = state.MarkOnPassageOfServiceStation;

            _context.Update(fromDb);
            _context.SaveChanges();

            return(Ok(state));
        }
        public IActionResult Edit(CarTechState model)
        {
            if (ModelState.IsValid)
            {
                var state = _context.CarTechStates.FirstOrDefault(c => c.CarTechStateId == model.CarTechStateId);

                if (state != null)
                {
                    state.CarId                         = model.CarId;
                    state.InspectorId                   = model.InspectorId;
                    state.Date                          = model.Date;
                    state.Mileage                       = model.Mileage;
                    state.BrakeSystem                   = model.BrakeSystem;
                    state.Suspension                    = model.Suspension;
                    state.Wheels                        = model.Wheels;
                    state.Lightning                     = model.Lightning;
                    state.AdditionalEquipment           = model.AdditionalEquipment;
                    state.MarkOnPassageOfServiceStation = model.MarkOnPassageOfServiceStation;

                    _context.CarTechStates.Update(state);
                    _context.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            return(View(model));
        }
Пример #4
0
        public IActionResult CarTechStates(CarTechState state)
        {
            ViewData["BrakeSystems"] = brakeSystems;

            var model = states
                        .Where(s => s.Suspension.StartsWith(state.Suspension ?? ""))
                        .Where(s => s.BrakeSystem == state.BrakeSystem);

            return(View(model));
        }
        public IActionResult Post([FromBody] CarTechState model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            _context.CarTechStates.Add(model);
            _context.SaveChanges();

            return(Ok(model));
        }
        public IActionResult Create(CarTechState model)
        {
            if (ModelState.IsValid)
            {
                _context.CarTechStates.Add(model);
                _context.SaveChanges();

                return(RedirectToAction("Index"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }