public static void AddCompany(AddCompanyForm rent) { using (var _context = new DiemServiceDB()) { User found = _context.UserDbSet.Where(user => user.Username == rent.OwnerUsername).FirstOrDefault(); switch (found.Role) { case Role.AdminAvio: AvioCompany toAdd = rent.getAvio(); string imgName = "avioCompany" + toAdd.Id; File.WriteAllBytes(AppDomain.CurrentDomain.BaseDirectory + "/" + imgName, Convert.FromBase64String(toAdd.Logo)); toAdd.Logo = imgName; toAdd.Owner = found; _context.AdminAvioDbSet.Include(x => x.OwnedAvioCompanies) .Where(x => x.Id == found.UlogaID) .FirstOrDefault().OwnedAvioCompanies .Add(_context.AvioCompanyDbSet.Add(toAdd)); break; case Role.AdminRentACar: RentACar toAdd2 = rent.getRent(); toAdd2.Owner = found; _context.AdminRentDbSet.Include(x => x.OwnedRentServices) .Where(x => x.Id == found.UlogaID) .FirstOrDefault().OwnedRentServices .Add(_context.RentACarDbSet.Add(toAdd2)); break; default: break; } _context.SaveChanges(); } }
private bool CheckQuickReservations(RentACar comp, Car car, string from, string to) { bool available = true; DateTime fromDate = DateTime.Parse(from); DateTime toDate = DateTime.Parse(to); List <DateTime> dates = GetDateTimeList(from, to); foreach (var res in comp.QuickReservations) { if (res.DiscountedCar.ID == car.ID) { foreach (var d in dates) { List <DateTime> pom = GetDateTimeList(res.Dates[0].DateStr, res.Dates[res.Dates.Count - 1].DateStr); if (pom.Contains(d)) { return(false); } } } } return(available); }
public void Insert(RentACar item) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = @"Server=DESKTOP-DK0K62G\SQLEXPRESS;Database=AutoTrade;User Id=sa;Password=010698;"; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = @" INSERT INTO RENTACAR( CarId, PricePerDay, Status ) VALUES ( @CarId, @PricePerDay, @Status )"; cmd.Parameters.AddWithValue("@CarId", item.CarId); cmd.Parameters.AddWithValue("@PricePerDay", item.PricePerDay); cmd.Parameters.AddWithValue("@Status", item.Status); try { conn.Open(); cmd.ExecuteNonQuery(); } finally { conn.Close(); } }
public ActionResult Edit(EditVm model) { if (!ModelState.IsValid) { return(View(model)); } RentACarRepository repo = new RentACarRepository(); RentACar item = new RentACar(); item.Id = model.Id; item.CarId = model.CarId; item.PricePerDay = model.PricePerDay; item.Status = model.Status; if (item.Id > 0) { repo.Update(item); } else { repo.Insert(item); } return(RedirectToAction("Index", "RentACar")); }
public async Task <ActionResult <TORentACar> > PostRentACar(TORentACar toRentACar) { string role = User.Claims.First(c => c.Type == "Roles").Value; if (role != "racAdmin" && role != "racAdminNew") { return(BadRequest("You are not authorised to do this action")); } RentACar rentACar = new RentACar(); rentACar.FromTO(toRentACar); _context.RentACars.Add(rentACar); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (RentACarExists(rentACar.Name)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetRentACar", new { id = toRentACar.Name }, toRentACar)); }
public void Update(RentACar item) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = @"Server=DESKTOP-DK0K62G\SQLEXPRESS;Database=AutoTrade;User Id=sa;Password=010698;"; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = @" UPDATE RENTACAR SET CarId = @CarId, PricePerDay = @PricePerDay, Status = @Status WHERE Id = @Id"; cmd.Parameters.AddWithValue("@CarId", item.CarId); cmd.Parameters.AddWithValue("@PricePerDay", item.PricePerDay); cmd.Parameters.AddWithValue("@Status", item.Status); cmd.Parameters.AddWithValue("@Id", item.Id); try { conn.Open(); cmd.ExecuteNonQuery(); } finally { conn.Close(); } }
public void RentACarPaymentEmail(string path, RentACar rentACar, PassengerInformation passenger) { try { //From Address var FromAddress = "*****@*****.**"; var FromAddressTitle = "*****@*****.**"; //To Address var toCustomer = passenger.Email; var ToAddressTitle = passenger.DisplayName; var Subject = "ImouRenACar (Car Rental Payment)."; //Smtp Server var smtpServer = new AppConfig().EmailServer; //Smtp Port Number var smtpPortNumber = new AppConfig().Port; var mimeMessageCustomer = new MimeMessage(); mimeMessageCustomer.From.Add(new MailboxAddress(FromAddressTitle, FromAddress)); mimeMessageCustomer.To.Add(new MailboxAddress(ToAddressTitle, toCustomer)); mimeMessageCustomer.Subject = Subject; var bodyBuilder = new BodyBuilder(); using (var data = File.OpenText(path)) { if (data.BaseStream != null) { //MANAGE CONTENT bodyBuilder.HtmlBody = data.ReadToEnd(); var body = bodyBuilder.HtmlBody; var replace = body.Replace("USER", passenger.DisplayName); replace = replace.Replace("URL", "http://imourentacar.com/rentacar/payment?bookingNumber=" + rentACar.BookingNumber); replace = replace.Replace("LOGO", "https://www.imourentacar.com/images/logo.png"); replace = replace.Replace("POLICY", "https://www.imourentacar.com/policy/index"); replace = replace.Replace("TC", "https://www.imourentacar.com/policy/index"); bodyBuilder.HtmlBody = replace; mimeMessageCustomer.Body = bodyBuilder.ToMessageBody(); } } using (var client = new MailKit.Net.Smtp.SmtpClient()) { client.Connect(smtpServer, smtpPortNumber); // Note: only needed if the SMTP server requires authentication // Error 5.5.1 Authentication client.Authenticate(new AppConfig().Email, new AppConfig().Password); client.Send(mimeMessageCustomer); client.Disconnect(true); } } catch (Exception e) { //ignore } }
public RentACar GetById(int id) { RentACar item = null; SqlConnection conn = new SqlConnection(); conn.ConnectionString = @"Server=DESKTOP-DK0K62G\SQLEXPRESS;Database=AutoTrade;User Id=sa;Password=010698;"; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = @" SELECT R.Id, CarId, C.Make+' '+C.Model AS CAR_NAME, C.Year AS CAR_YEAR, PricePerDay, Status FROM RENTACAR R JOIN CARS C ON R.CarId=C.Id WHERE R.Id = @Id "; cmd.Parameters.AddWithValue("@Id", id); SqlDataReader reader = null; try { conn.Open(); reader = cmd.ExecuteReader(); if (reader.Read()) { item = new RentACar(); item.Id = Convert.ToInt32(reader["Id"]); item.CarId = Convert.ToInt32(reader["CarId"]); item.CarName = Convert.ToString(reader["CAR_NAME"]); item.CarYear = Convert.ToInt32(reader["CAR_YEAR"]); item.PricePerDay = Convert.ToDecimal(reader["PricePerDay"]); item.Status = Convert.ToString(reader["Status"]); } } finally { reader.Close(); conn.Close(); } return(item); }
public async Task <object> Put(int id, [FromBody] RentACar model) { var user = await GetLoginUserAsync(); if (user is RentACarAdministrator) { await repository.UpdateAsync(model); return(Ok()); } return(Forbid()); }
public async Task <ActionResult <RentACar> > UpdateRent(RentACar renta) { RentACar r = await _context.Rente.FindAsync(renta.Naziv); r.Grad = renta.Grad; r.Drzava = renta.Drzava; r.Adresa = renta.Adresa; r.Opis = renta.Opis; _context.Rente.Update(r); await _context.SaveChangesAsync(); return(r); }
public List <RentACar> GetAll() { List <RentACar> items = new List <RentACar>(); SqlConnection conn = new SqlConnection(); conn.ConnectionString = @"Server=DESKTOP-DK0K62G\SQLEXPRESS;Database=AutoTrade;User Id=sa;Password=010698;"; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = @" SELECT R.Id, CarId, C.Make+' '+C.Model AS CAR_NAME, C.Year AS CAR_YEAR, PricePerDay, Status FROM RENTACAR R JOIN CARS C ON R.CarId=C.Id ORDER BY CarId "; SqlDataReader reader = null; try { conn.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { RentACar item = new RentACar(); item.Id = Convert.ToInt32(reader["Id"]); item.CarId = Convert.ToInt32(reader["CarId"]); item.CarName = Convert.ToString(reader["CAR_NAME"]); item.CarYear = Convert.ToInt32(reader["CAR_YEAR"]); item.PricePerDay = Convert.ToDecimal(reader["PricePerDay"]); item.Status = Convert.ToString(reader["Status"]); items.Add(item); } } finally { reader.Close(); conn.Close(); } return(items); }
public ActionResult Edit(int?id) { RentACarRepository repo = new RentACarRepository(); RentACar item = id == null ? new RentACar() : repo.GetById(id.Value); EditVm model = new EditVm(); model.Id = item.Id; model.CarId = item.CarId; model.PricePerDay = item.PricePerDay; model.Status = item.Status; return(View(model)); }
public async Task <ActionResult <RentACar> > AddRent(RentACar rent) { if (!RentExists(rent.Naziv)) { _context.Rente.Add(rent); await _context.SaveChangesAsync(); return(CreatedAtAction("GetRent", new { naziv = rent.Naziv }, rent)); } else { return(new StatusCodeResult((int)HttpStatusCode.BadRequest)); } }
public async Task <bool> AddAsync(RentACar rentACar) { var r = await context.FindAsync <RentACar>(rentACar.Id); if (r is object) { return(false); } await context.AddAsync(rentACar); await context.SaveChangesAsync(); return(true); }
private bool CheckBranch(RentACar company, string location) { if (company.MainLocation.FullAddress.ToLower().Trim().Contains(location.Trim().ToLower())) { return(true); } bool exists = false; foreach (var loc in company.Locations) { if (loc.FullAddress.ToLower().Trim().Contains(location.Trim().ToLower())) { exists = true; break; } } return(exists); }
public bool DodajRentacarServis(RentACar rent) { var servisi = _dbContext.RentACar.ToList(); var korisnici = _dbContext.Korisnici.ToList(); var servis = _dbContext.RentACar.Where(a => a.RentacarId == rent.RentacarId).FirstOrDefault(); if (servis != null) { return(false); } foreach (var s in servisi) { foreach (var k in korisnici) { if (k.Id == s.KorisnikId) { return(false); } } } try { _dbContext.RentACar.Add(new RentACar { Lokacije = rent.Lokacije, Naziv = rent.Naziv, Opis = rent.Opis, Adresa = rent.Adresa, KorisnikId = rent.KorisnikId }); } catch (Exception e) { Console.WriteLine("Greska pri dodavanju servisa", e); } _dbContext.SaveChanges(); return(true); }
public RentACar getRentACarInfo(int RentACarId) { try { var rentACar = new RentACar(); var rentACars = _dbContext.RentACar.Where(x => x.RentacarId == RentACarId).FirstOrDefault(); var car = _dbContext.Vozila.Where(x => x.RentACarId == RentACarId) .Select(cars => new Vozilo() { RentACarId = cars.RentACarId, Marka = cars.Marka, Model = cars.Model, GodinaProizvodnje = cars.GodinaProizvodnje, BrojSjedista = cars.BrojSjedista, TipVozila = cars.TipVozila, Cijena = cars.Cijena, Image = cars.Image, Slobodno = cars.Slobodno, TipGoriva = cars.TipGoriva, Transmisija = cars.Transmisija, VoziloId = cars.VoziloId }).ToList(); rentACar.RentacarId = rentACars.RentacarId; rentACar.Adresa = rentACars.Adresa; rentACar.Lokacije = rentACars.Lokacije; rentACar.Naziv = rentACars.Naziv; rentACar.Ocjena = rentACars.Ocjena; rentACar.Opis = rentACars.Opis; rentACar.Ocjena = rentACars.Ocjena; rentACar.Vozila = car; return(rentACar); } catch (Exception e) { var message = e.Message; Console.WriteLine(message); return(null); } }
public async Task <object> Post([FromBody] RentACar model) { var user = await GetLoginUserAsync(); if (user is SystemAdministrator) { var rentacar = new RentACar() { Address = model.Address, Description = model.Description, Name = model.Name }; if (!await repository.AddAsync(rentacar)) { return(BadRequest(new { message = "Already exist" })); } return(Ok()); } return(Forbid()); }
public bool IzmijeniRentacarServis(int id, RentACar rent) { try { var rentacar = _dbContext.RentACar.FirstOrDefault(c => c.RentacarId == id); if (rentacar != null) { rentacar.Opis = rent.Opis; rentacar.Naziv = rent.Naziv; rentacar.Lokacije = rent.Lokacije; rentacar.Adresa = rent.Adresa; _dbContext.SaveChanges(); return(true); } return(false); } catch (Exception) { return(false); } }
public async Task <IActionResult> IzmijeniRentacarServis(int rentacarId, [FromBody] RentACar rent) { var x = _rentACarService.IzmijeniRentacarServis(rentacarId, rent); return(Ok(x)); }
public async Task <IActionResult> DodajVozilo([FromBody] RentACar rent) { var x = _rentACarService.DodajRentacarServis(rent); return(Ok(x)); }
public void Update(RentACar entity) { throw new NotImplementedException(); }
public async Task <IActionResult> PutRentACar(string id, TORentACar toRentACar) { string role = User.Claims.First(c => c.Type == "Roles").Value; if (role != "racAdmin" && role != "racAdminNew") { return(BadRequest("You are not authorised to do this action")); } var rentACar = await _context.RentACars.Include(r => r.Locations).Include(r => r.Prices).FirstOrDefaultAsync(r => r.Name == id); RentACar modifiedRentACar = new RentACar(); modifiedRentACar.FromTO(toRentACar); if (id != rentACar.Name) { return(BadRequest()); } //_context.Entry(rentACar).State = EntityState.Modified; _context.Entry(rentACar).CurrentValues.SetValues(modifiedRentACar); #region Update Locations var locations = rentACar.Locations.ToList(); //Lokacije iz baze foreach (var location in locations) { var loc = toRentACar.Locations.SingleOrDefault(l => l.Value.ToString() == location.LocationValue); //Ako ne postoji u bazi ta lokacija, ukloni je if (loc == null) { _context.Remove(location); } } // add the new items foreach (var location in toRentACar.Locations.ToList()) //Nove lokacije { if (locations.All(l => l.LocationValue != location.Value.ToString())) //Ako sve lokacije nisu jednake novoj lokaciji, dodaj je { rentACar.Locations.Add(new Location() { LocationId = 0, LocationValue = location.Value.ToString(), RentACar = rentACar }); } } #endregion #region Update Prices var prices = rentACar.Prices.ToList(); //Cene iz baze var carPrice = prices.SingleOrDefault(p => p.PriceService == "Car"); carPrice.PriceValue = (Int64)toRentACar.Prices.ToList()[0].Value; var vanPrice = prices.SingleOrDefault(p => p.PriceService == "Van"); vanPrice.PriceValue = (Int64)toRentACar.Prices.ToList()[1].Value; var truckPrice = prices.SingleOrDefault(p => p.PriceService == "Truck"); truckPrice.PriceValue = (Int64)toRentACar.Prices.ToList()[2].Value; _context.Entry(prices[0]).CurrentValues.SetValues(carPrice); _context.Entry(prices[1]).CurrentValues.SetValues(vanPrice); _context.Entry(prices[2]).CurrentValues.SetValues(truckPrice); #endregion try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RentACarExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task UpdateAsync(RentACar rentACar) { context.Update(rentACar); await context.SaveChangesAsync(); }
public static void SeedCompanies(ApplicationUsersContext context) { if (context.RentACarCompanies.Count() != 0) { return; } Address addr1 = new Address() { FullAddress = "Bulevar Oslobodjenja 81, Novi Sad, Serbia", Latitude = 45.254152, Longitude = 19.836035 }; Address addr2 = new Address() { FullAddress = "Blok 28, Belgrade, Serbia", Latitude = 44.812298, Longitude = 20.417439 }; RentACar company1 = new RentACar(); company1.Activated = true; company1.AvrageRating = 0; company1.Cars = new List <Car>(); company1.Description = "No description"; company1.extras = new List <ExtraAmenity>(); company1.Image = "kompanija1.jpg"; company1.Locations = new List <Address>() { addr1, addr2 }; company1.MainLocation = new Address() { FullAddress = "Vukovarska 2, Belgrade, Serbia", Latitude = 44.792089, Longitude = 20.430300 }; company1.Name = "National Car Rental"; company1.QuickReservations = new List <QuickReservation>(); company1.Ratings = new List <Rating>(); ExtraAmenity amenity1 = new ExtraAmenity(); amenity1.Name = "Additional driver"; amenity1.Image = "addDriver2.png"; amenity1.Price = 100; amenity1.OneTimePayment = false; ExtraAmenity amenity2 = new ExtraAmenity(); amenity2.Name = "GPS Navigation"; amenity2.Image = "GPS2.png"; amenity2.Price = 20; amenity2.OneTimePayment = true; ExtraAmenity amenity3 = new ExtraAmenity(); amenity3.Name = "Unlimited miles"; amenity3.Image = "UnlimitedMiles2.png"; amenity3.Price = 80; amenity3.OneTimePayment = true; ExtraAmenity amenity4 = new ExtraAmenity(); amenity4.Name = "Child & baby seats"; amenity4.Image = "childSeats2.png"; amenity4.Price = 40; amenity4.OneTimePayment = true; ExtraAmenity amenity5 = new ExtraAmenity(); amenity5.Name = "WiFi hotspot device"; amenity5.Image = "wifi2.png"; amenity5.Price = 25; amenity5.OneTimePayment = true; ExtraAmenity amenity6 = new ExtraAmenity(); amenity6.Name = "Car rental protection plan"; amenity6.Image = "protectionPlan2.png"; amenity6.Price = 75; amenity6.OneTimePayment = true; ExtraAmenity amenity7 = new ExtraAmenity(); amenity7.Name = "Prepaid fuel"; amenity7.Image = "fuel2.png"; amenity7.Price = 30; amenity7.OneTimePayment = true; ExtraAmenity amenity8 = new ExtraAmenity(); amenity8.Name = "Extended roadside protection"; amenity8.Image = "roadsideProtection2.png"; amenity8.Price = 65; amenity8.OneTimePayment = true; ExtraAmenity amenity9 = new ExtraAmenity(); amenity9.Name = "Winter tires & snow chains"; amenity9.Image = "snow2.png"; amenity9.Price = 50; amenity9.OneTimePayment = true; ExtraAmenity amenity10 = new ExtraAmenity(); amenity10.Name = "Delivery & collection"; amenity10.Image = "driver2.png"; amenity10.Price = 100; amenity10.OneTimePayment = true; List <ExtraAmenity> amenities = new List <ExtraAmenity>(); amenities.Add(amenity1); amenities.Add(amenity2); amenities.Add(amenity3); amenities.Add(amenity4); amenities.Add(amenity5); amenities.Add(amenity6); amenities.Add(amenity7); amenities.Add(amenity8); amenities.Add(amenity9); amenities.Add(amenity10); company1.extras = amenities; context.RentACarCompanies.Add(company1); context.SaveChanges(); List <RentACar> companies = context.RentACarCompanies.ToList(); Car car1 = new Car(); car1.AvrageRating = 0; car1.Brand = "Ford"; car1.CompanyId = companies[0].ID; car1.Image = "fusion.jpg"; car1.Location = addr1.FullAddress; car1.Model = "Fusion"; car1.Passengers = 5; car1.PricePerDay = 70; car1.Ratings = new List <Rating>(); car1.RentedDates = new List <Date>(); car1.Type = "full-size"; car1.Year = 2015; car1.Removed = false; Car car2 = new Car(); car2.AvrageRating = 0; car2.Brand = "WW"; car2.CompanyId = companies[0].ID; car2.Image = "audia4.jpg"; car2.Location = addr2.FullAddress; car2.Model = "Audi A4"; car2.Passengers = 5; car2.PricePerDay = 85; car2.Ratings = new List <Rating>(); car2.RentedDates = new List <Date>(); car2.Type = "standard-size"; car2.Year = 2015; car2.Removed = false; companies[0].Cars = new List <Car>(); companies[0].Cars.Add(car1); companies[0].Cars.Add(car2); context.RentACarCompanies.Update(companies[0]); context.SaveChanges(); }
public void Add(RentACar car) { Console.WriteLine("EF ile eklendi"); }
public void Add(RentACar car) { Console.WriteLine("Ado.Net ile eklendi."); }