private static void InsertCategories() { var categories = new List <Category>() { new Category { Name = "Auto" }, new Category { Name = "Camion" }, new Category { Name = "Moto" } }; categories .ForEach(p => { if (!_context.Categories.Any(x => x.Name == p.Name)) { _context.Add(p); } }); _context.SaveChanges(); }
public CarResponse EnterCar(string RegNo) { CarResponse toReturn = new CarResponse { Success = true, Message = "The car has been inserted" }; Car carItem = new Car { RegNo = RegNo, StartDate = DateTime.Now }; if (_parkingContext.Cars.Count() >= 10) { toReturn.Success = false; toReturn.Message = "The parking is full"; } if (_parkingContext.Cars.Count(a => a.RegNo == RegNo) > 0) { toReturn.Success = false; toReturn.Message = "This car is already parked here"; } if (toReturn.Success) { carItem.StartDate = DateTime.Now; _parkingContext.Add(carItem); _parkingContext.SaveChanges(); } return(toReturn); }
public async Task <IActionResult> Create([Bind("Id,Number")] ParkingLot parkingLot) { if (ModelState.IsValid) { _context.Add(parkingLot); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(parkingLot)); }
public async Task <IActionResult> Create([Bind("Ime,Prezime,Email,DatumRodjenja,Password,JeAktivan,DatumKreiranja,Uloga")] Korisnik korisnik) { if (ModelState.IsValid) { _context.Add(korisnik); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(korisnik)); }
public async Task <IActionResult> Create([Bind("Id,InicioVigencia,FimVigencia,ValorHoraInical,ValorHoraAdicional")] PriceTable priceTable) { if (ModelState.IsValid) { _context.Add(priceTable); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(priceTable)); }
public object ParkStatus(ParkingStatus parkingStatus) { try { double total = db.parkingPortals.Where(p => p.ReceiptNo == parkingStatus.ReceiptNo) .Select(i => (DateTime.Now.Subtract(i.ParkingDate).TotalMinutes)).Sum(); parkingStatus.Date = DateTime.Now; parkingStatus.Charges = Convert.ToInt32(total * 10); var Status = db.parkingPortals.Find(parkingStatus.ReceiptNo); Status.Status = "UnPark"; db.parkingPortals.Update(Status); db.Add(parkingStatus); db.SaveChanges(); var data = (from p in db.parkingPortals where p.ReceiptNo == parkingStatus.ReceiptNo from q in db.ParkingStatuses select new { p.ReceiptNo, p.DriverName, p.Brand, p.VehicleColor, p.Slot, p.VehicleNumber, p.ParkingDate, parkingStatus.Date, parkingStatus.Charges }).FirstOrDefault(); return(data); } catch (Exception e) { throw new Exception(e.Message); } }
public UserDetail AddUserData(UserDetail UserDetail) { try { db.Add(UserDetail); db.SaveChanges(); return(UserDetail); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <IActionResult> Create([Bind("Id,Placa,HoraEntrada,HoraSaida,Duracao,QtdHorasCobradas,ValorHora")] VehicleControl vehicleControl) { if (ModelState.IsValid) { vehicleControl.HoraSaida = vehicleControl.HoraEntrada; _context.Add(vehicleControl); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vehicleControl)); }
public async Task <IActionResult> Create([Bind("Id,Model,Plate,Input")] Vehicle vehicle) { var agora = DateTime.Now; ViewData["now"] = agora.ToString("dd/MM/yyyy"); if (ModelState.IsValid) { _context.Add(vehicle); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vehicle)); }