public async Task <Object> AddReservation(RezervacijaModel model)//"2020-06-13" "10:00" { var car = await _context.Cars .Include(rezervacija => rezervacija.RezervacijeAutaOdDo) .FirstOrDefaultAsync(i => i.idCar.ToString() == model.idCar); //var user = await _context.Users // .Include(rezervacijaUser => rezervacijaUser.rentACarReservation) // .FirstOrDefaultAsync(iUser => iUser.Id.ToString() == model.idUser); if (car == null) { return(BadRequest()); } string[] datum; datum = model.startDay.Split('-'); string[] vreme; vreme = model.startTime.Split(':'); RezervacijaOdDo rez = new RezervacijaOdDo(); rez.Od = new DateTime(Int32.Parse(datum[0]), Int32.Parse(datum[1]), Int32.Parse(datum[2]), Int32.Parse(vreme[0]), Int32.Parse(vreme[1]), 0); rez.Do = new DateTime(Int32.Parse(model.endDay.Split('-')[0]), Int32.Parse(model.endDay.Split('-')[1]), Int32.Parse(model.endDay.Split('-')[2]), Int32.Parse(model.endTime.Split(':')[0]), Int32.Parse(model.endTime.Split(':')[1]), 0); rez.deleted = false; car.RezervacijeAutaOdDo.Add(rez); //user.rentACarReservation.Add(rez); try { await _context.SaveChangesAsync(); } #pragma warning disable CS0168 // The variable 'e' is declared but never used catch (Exception e) #pragma warning restore CS0168 // The variable 'e' is declared but never used { throw; } return(car); }
public async Task <Object> AddBranch(Branch model) { var rentACarService = await _context.RentACarServices .Include(cars => cars.RACServiceCars) .Include(ocene => ocene.RACOcene) .Include(address => address.RACBranches) .Include(comments => comments.RACComments) .FirstOrDefaultAsync(i => i.idRAC == model.idService); if (rentACarService == null) { return(BadRequest()); } var adr = new Address(); adr.streetAndNumber = model.streetAndNumber; adr.city = model.city; adr.country = model.country; adr.deleted = false; //_context.Addresses.Add(adr); rentACarService.RACBranches.Add(adr); try { await _context.SaveChangesAsync(); } #pragma warning disable CS0168 // The variable 'e' is declared but never used catch (Exception e) #pragma warning restore CS0168 // The variable 'e' is declared but never used { throw; } return(adr); }
public async Task <Object> AddRACService(RentACarModel model) { //int id = Int32.Parse(model.idAdmin); User tmpUser = await _context.Users .Include(address => address.address) //.Include(friends => friends.friends) //.Include(friendRequests => friendRequests.friendRequests) .FirstOrDefaultAsync(i => i.Id == model.idAdmin); if (tmpUser == null) { return(BadRequest("Ne postoji korisnik!")); } RentACarService rac = new RentACarService(); Address adr = new Address(); Cenovnik cen = new Cenovnik(); cen.StavkeCenovnika = new List <StavkaCenovnika>(); StavkaCenovnika stavka1 = new StavkaCenovnika(); StavkaCenovnika stavka2 = new StavkaCenovnika(); StavkaCenovnika stavka3 = new StavkaCenovnika(); StavkaCenovnika stavka4 = new StavkaCenovnika(); StavkaCenovnika stavka5 = new StavkaCenovnika(); rac.Name = model.Name; rac.Description = model.Description; rac.LogoImage = model.LogoImage; adr.city = model.city; adr.country = model.country; adr.streetAndNumber = model.streetAndNumber; adr.deleted = false; rac.RACAddress = adr; stavka1.Naziv = "BabySeat"; stavka1.Vrednost = Int32.Parse(model.BabySeat); stavka1.deleted = false; cen.StavkeCenovnika.Add(stavka1); stavka2.Naziv = "Navigation"; stavka2.Vrednost = Int32.Parse(model.Navigation); stavka2.deleted = false; cen.StavkeCenovnika.Add(stavka2); stavka3.Naziv = "Roof"; stavka3.Vrednost = Int32.Parse(model.Roof); stavka3.deleted = false; cen.StavkeCenovnika.Add(stavka3); stavka4.Naziv = "Luxuary"; stavka4.Vrednost = Int32.Parse(model.Luxuary); stavka4.deleted = false; cen.StavkeCenovnika.Add(stavka4); stavka5.Naziv = "Discount"; stavka5.Vrednost = Int32.Parse(model.Discount); stavka5.deleted = false; cen.StavkeCenovnika.Add(stavka5); cen.deleted = false; rac.Cenovnik = cen; rac.RACidAdmin = tmpUser.Id; Grad pom = await _context.Gradovi .FirstOrDefaultAsync(i => i.city == adr.city); if (pom == null) { Grad grad = new Grad(); grad.city = adr.city; grad.description = "Promotivni opis. . ."; grad.images = model.LogoImage; _context.Gradovi.Add(grad); } _context.RentACarServices.Add(rac); try { await _context.SaveChangesAsync(); } #pragma warning disable CS0168 // The variable 'e' is declared but never used catch (Exception e) #pragma warning restore CS0168 // The variable 'e' is declared but never used { throw; } return(rac); }
public async Task <Object> AddCar(CarModel carModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var rentACarService = await _context.RentACarServices .Include(cars => cars.RACServiceCars) .Include(ocene => ocene.RACOcene) .Include(address => address.RACBranches) .Include(comments => comments.RACComments) .FirstOrDefaultAsync(i => i.idRAC == carModel.idService); if (rentACarService == null) { return(BadRequest()); } Car car = new Car(); car.Model = carModel.Model; car.Brand = ReturnBrand(carModel.Brand); car.Type = ReturnType(carModel.Type); car.Gear = ReturnGear(carModel.Gear); car.Fuel = ReturnFuel(carModel.Fuel); car.Doors = ReturnDoor(carModel.Doors); car.Seats = ReturnSeat(carModel.Seats); car.Year = new DateTime(Int32.Parse(carModel.Year)); car.Kw = Int32.Parse(carModel.Kw); double d = car.Kw * 1.56; car.Cm3 = Int32.Parse(Math.Ceiling(d).ToString()); if (car.Seats == SeatsCarEnum.Two) { car.FreeSeats = 2; } else if (car.Seats == SeatsCarEnum.Four) { car.FreeSeats = 4; } else if (car.Seats == SeatsCarEnum.Five) { car.FreeSeats = 5; } else if (car.Seats == SeatsCarEnum.Six) { car.FreeSeats = 6; } else { car.FreeSeats = 7; } car.Trunk = Int32.Parse(carModel.Trunk); car.PricePerDay = Double.Parse(carModel.Price); car.CarImage = carModel.CarImg; car.BabySeat = StringToBool(carModel.BabySeat); car.Navigation = StringToBool(carModel.Navigation); car.RoofRack = StringToBool(carModel.RoofRack); car.deleted = false; //_context.Cars.Add(car); rentACarService.RACServiceCars.Add(car); try { await _context.SaveChangesAsync(); } #pragma warning disable CS0168 // The variable 'e' is declared but never used catch (Exception e) #pragma warning restore CS0168 // The variable 'e' is declared but never used { throw; } //var cars = await _context.Cars.Where(x => x.deleted == false) // .Include(ocene => ocene.OceneAuta) // .Include(rezervacije => rezervacije.RezervacijeAutaOdDo) // .ToListAsync(); return(car); #pragma warning disable CS0162 // Unreachable code detected string message = "Uspesno"; #pragma warning restore CS0162 // Unreachable code detected return(Ok(new { message })); //return CreatedAtAction("GetFlight", new { id = flight.id }, flight); return(BadRequest()); }