public CarRentRegister AddCarRent(CarRentRegister carRentToBeAdded) { var addedCarRent = carRentContext.Add(carRentToBeAdded); carRentContext.SaveChanges(); return(addedCarRent.Entity); }
public Customers AddCustomer(Customers customerToBeAdded) { var addedCustomer = carRentContext.Add(customerToBeAdded); carRentContext.SaveChanges(); return(addedCustomer.Entity); }
public IActionResult AddCar([FromQuery] CarModel model) { if (ModelState.IsValid) { _context.Cars.Add(_mapper.Map <Car>(model)); _context.SaveChanges(); } else { return(BadRequest()); } return(Ok()); }
public string CreateRentDispositon(CarRentDisposition dispositionToCreate) { using (var context = new CarRentContext()) { int clientId; var existingClient = context.Clients.FirstOrDefault(x => x.DriverLicense == dispositionToCreate.Client.DriverLicense); if (existingClient == null) { var clientToCreate = new Client() { FirstName = dispositionToCreate.Client.FirstName, LastName = dispositionToCreate.Client.LastName, DriverLicense = dispositionToCreate.Client.DriverLicense }; context.Clients.Add(clientToCreate); context.SaveChanges(); clientId = clientToCreate.Id; } else { clientId = existingClient.Id; } int carId; var existingCar = context.Cars.FirstOrDefault(x => x.Brand == dispositionToCreate.Car.Brand && x.Name == dispositionToCreate.Car.CarName && x.Colour == dispositionToCreate.Car.Colour && x.Price == dispositionToCreate.Car.Price); if (existingCar == null) { carId = 1; } else { carId = existingCar.Id; } var rentDisposition = new RentDisposition() { ClientId = clientId, CarId = carId, CreatedOn = DateTime.Now }; context.RentDispostions.Add(rentDisposition); context.SaveChanges(); } return("Success"); }
public IActionResult AddPayment([FromQuery] PaymentModel model) { if (ModelState.IsValid) { _context.Payments.Add(_mapper.Map <Payment>(model)); _context.SaveChanges(); } else { return(BadRequest()); } return(Ok()); }
public Model.Rent Insert(RentInsert request) { var rents = _context.Rents.Where(w => w.VehicleId == request.VehicleId).Where(w => w.StartDate <= request.StartDate && w.EndDate >= request.StartDate || w.EndDate <= request.EndDate && w.EndDate >= request.EndDate).ToList(); if (rents.Count == 0) { var newRent = _mapper.Map <Database.Rent>(request); _context.Rents.Add(newRent); _context.SaveChanges(); return(_mapper.Map <Model.Rent>(newRent)); } else { return(null); } }
public Model.User AddUser(AddUserRequest req) { var validate = _context.Users.FirstOrDefault(w => w.Username == req.Username); if (validate != null) { return(null); } var user = _mapper.Map <Database.User>(req); user.PasswordSalt = HashGenerator.GenerateSalt(); user.PasswordHash = HashGenerator.GenerateHash(user.PasswordSalt, req.Password); user.RoleId = req.RoleId; user.CityId = req.CityId; _context.Users.Add(user); _context.SaveChanges(); return(_mapper.Map <Model.User>(user)); }
public IActionResult Post([FromBody] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(Ok(user)); } return(BadRequest(ModelState)); }
public string CreateCar(CarPub carToCreate) { using (var context = new CarRentContext()) { context.Cars.Add(new Model.Car() { Brand = carToCreate.Brand, Colour = carToCreate.Colour, Name = carToCreate.CarName, Price = carToCreate.Price }); context.SaveChanges(); } return("Success"); }