public IEnumerable <Hotel> GetAllHotels() { using (var hotelsContext = new HotelsContext()) { var hotels = hotelsContext.Hotels.ToList(); return(hotels); } }
public IEnumerable <Reservation> GetAllReservation() { using (HotelsContext context = new HotelsContext(_options)) { var reservationBooking = context.Reservations; return(reservationBooking?.ToList()); } }
protected void Page_Load(object sender, System.EventArgs e) { if (!string.IsNullOrEmpty(Output.Text)) { Output.Text = ""; } Submit.Click += Submit_Click; using HotelsContext context = new HotelsContext(); users.AddRange(from u in context.User.AsEnumerable() select new LoginUser(null, u.Login, u.PasswordHash)); }
protected void Page_Load(object sender, System.EventArgs e) { if (!string.IsNullOrEmpty(Output.Text)) { Output.Text = ""; } LoginPage.Click += LoginPage_Click; Submit.Click += Submit_Click; using HotelsContext context = new HotelsContext(); users.AddRange(from user in context.User.AsEnumerable() select user); }
protected void Page_Load(object sender, System.EventArgs e) { if (!string.IsNullOrEmpty(Output.Text)) { Output.Text = ""; } Change.Click += Change_Click; using HotelsContext c = new HotelsContext(); users.AddRange(from u in c.User select u); Data.UserId = (from u in c.User.AsEnumerable() where Utils.MakeToken(u.Login, u.PasswordHash) == Request.Cookies["token"].Value select u.Id).First(); }
public HttpResponseMessage Post([FromBody] NewHotelModel m) { using (HotelsContext c = new HotelsContext()) { c.Hotel.Add(new Hotel() { Name = m.Name, City = m.City, Address = m.Address, Rating = m.Rating }); c.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } }
public async Task DeleteReservation(int reservationId) { using (HotelsContext context = new HotelsContext(_options)) { var reservation = context.Reservations.FirstOrDefault(b => b.ReservationId == reservationId); if (reservation != null) { context.Reservations.Remove(reservation); await context.SaveChangesAsync(); } } }
public static void Initialize(HotelsContext context) { if (context.Database.EnsureCreated()) { context.Hotels.Add(new Hotel { Id = 1, HotelName = "Leonardo", Address = "Jones Street 259, Manhattan", IsFullyBooked = false, Stars = 5 }); context.Hotels.Add(new Hotel { Id = 2, HotelName = "Dan", Address = "Bleecker Street 23, Manhattan", IsFullyBooked = true, Stars = 3.5 }); context.SaveChanges(); } }
public HttpResponseMessage Get(int id) { using (HotelsContext c = new HotelsContext()) { Hotel hotel = (from h in c.Hotel where h.Id == id select h).FirstOrDefault(); if (hotel == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } HotelModel model = new HotelModel(hotel.Id, hotel.Name, hotel.City, hotel.Address, hotel.Rating); return(Request.CreateResponse(HttpStatusCode.OK, model, Configuration.Formatters.JsonFormatter)); } }
public IEnumerable <Room> GetAvaliabileByDate(DateTime date) { using (HotelsContext context = new HotelsContext(_options)) { var roomsWithoutReservation = (from reservation in context.Reservations where date <reservation.CheckIn || date> reservation.CheckOut select reservation.Room) .ToList(); return(roomsWithoutReservation); } }
public HttpResponseMessage Put(int id, [FromBody] NewHotelModel m) { using (HotelsContext c = new HotelsContext()) { Hotel h = (from hotel in c.Hotel where hotel.Id == id select hotel).FirstOrDefault(); if (h == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } h.Name = m.Name; h.City = m.City; h.Address = m.Address; h.Rating = m.Rating; c.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } }
public IEnumerable <Room> GetAvailableByDate(DateTime date) { using (HotelsContext context = new HotelsContext(_options)) { var roomsWithoutReservation = (from room in context.Rooms join reservation in context.Reservations on room equals reservation.Room into result from reservation in result.DefaultIfEmpty() where (date <reservation.CheckIn || date> reservation.CheckOut) || room.Reservations.Count == 0 select room).ToList(); return(roomsWithoutReservation); } }
private void Save_Click(object sender, System.EventArgs e) { using HotelsContext c = new HotelsContext(); foreach (User user in users) { if (Utils.MakeToken(user.Login, user.PasswordHash) == Request.Cookies["token"].Value) { c.Booking.Add(new Booking() { RoomId = RoomId, DateBegin = Data.BeginDate, DateEnd = Data.EndDate, UserId = user.Id }); c.SaveChanges(); Response.Redirect("Bookings.aspx"); return; } } }
private void Save_Click(object sender, System.EventArgs e) { string errors = Utils.CheckUserData(Data.UserId, Data.Login, Data.Name, Data.Surname, Data.Email, Data.Phone, users); if (errors.Length == 0) { using (HotelsContext context = new HotelsContext()) { User u = (from user in context.User where user.Id == Data.UserId select user).First(); u.Login = Data.Login; u.Name = Data.Name; u.Surname = Data.Surname; u.Email = Data.Email; u.Phone = Data.Phone; context.SaveChanges(); Response.Redirect("UsersPage.aspx"); return; } } Output.Text = "Edit credentials (" + errors + ") have been rejected"; Output.ForeColor = System.Drawing.Color.Red; }
public HotelsController(HotelsContext context) { if (_context == null) { _context = context; } if (hm == null) { hm = new HotelManage(); _context.Hotel.AddRange(hm._hotels); _context.Room.AddRange(hm._rooms); _context.Reservations.AddRange(hm._reservations); _context.SaveChanges(); } }
private void Change_Click(object sender, System.EventArgs e) { string errors = Utils.CheckUserData(Data.UserId, Data.Login, Data.Name, Data.Surname, Data.Email, Data.Phone, users); if (errors.Length == 0) { using (HotelsContext c = new HotelsContext()) { User u = (from user in c.User where user.Id == Data.UserId select user).First(); u.Login = Data.Login; u.Name = Data.Name; u.Surname = Data.Surname; u.Email = Data.Email; u.Phone = Data.Phone; c.SaveChanges(); Response.Cookies["token"].Value = Utils.MakeToken(u.Login, u.PasswordHash); Response.Redirect("Hotels.aspx"); return; } } Output.Text = "New profile credentials (" + errors + ") have been rejected"; Output.ForeColor = System.Drawing.Color.Red; }
public HttpResponseMessage Delete(int id) { try { using (HotelsContext c = new HotelsContext()) { Hotel hotel = (from h in c.Hotel where h.Id == id select h).FirstOrDefault(); if (hotel == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } c.Hotel.Remove(hotel); c.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } catch (System.Data.Entity.Infrastructure.DbUpdateException dbex) { return(Request.CreateResponse(HttpStatusCode.Conflict, dbex.ToString())); } }
private void Add_Click(object sender, System.EventArgs e) { string errors = Utils.CheckUserData(Data.UserId, Data.Login, Data.Name, Data.Surname, Data.Email, Data.Phone, users); if (errors.Length == 0) { using (HotelsContext c = new HotelsContext()) { c.User.Add(new User { RoleId = 2, Login = Data.Login, Name = Data.Name, Surname = Data.Surname, Email = Data.Email, Phone = Data.Phone, PasswordHash = Utils.ConvertToSHA512(Password.Text) }); c.SaveChanges(); Response.Redirect("UsersPage.aspx"); return; } } Output.Text = "Add credentials (" + errors + ") have been rejected"; Output.ForeColor = System.Drawing.Color.Red; }
private void Submit_Click(object sender, System.EventArgs e) { string errors = Utils.CheckUserData(0, LogIn.Text, Name.Text, Surname.Text, Email.Text, Phone.Text, users); errors += Pwd.Text != Pwd2.Text || string.IsNullOrEmpty(Pwd.Text) || string.IsNullOrEmpty(Pwd2.Text) ? ", password" : ""; if (errors.Length == 0) { using HotelsContext context = new HotelsContext(); context.User.Add(new User() { RoleId = 2, Login = LogIn.Text, Name = Name.Text, Surname = Surname.Text, Email = Email.Text, Phone = Phone.Text, PasswordHash = Utils.ConvertToSHA512(Pwd.Text) }); context.SaveChanges(); LoginPage_Click(null, null); return; } Output.Text = "Register credentials (" + errors + ") have been rejected"; Output.ForeColor = System.Drawing.Color.Red; }
private void Submit_Click(object sender, System.EventArgs e) { using HotelsContext context = new HotelsContext(); Output.ForeColor = System.Drawing.Color.Red; if (NewPwd.Text != NewPwd2.Text) { Output.Text = "New password is not equal to confirmation"; return; } foreach (LoginUser user in users) { if (Utils.MakeToken(user.Login, Utils.ConvertToSHA512(CurPwd.Text)) == Request.Cookies["token"].Value) { User us = (from u in context.User where u.Login == user.Login select u).First(); us.PasswordHash = Utils.ConvertToSHA512(NewPwd.Text); context.SaveChanges(); Request.Cookies["token"].Value = Utils.MakeToken(us.Login, us.PasswordHash); Response.Redirect("Hotels.aspx"); return; } } Output.Text = "Wrong password has been entered"; }
public void Test1() { //Arrange var destinationId = fixture.Create <int>(); var nights = fixture.Create <int>(); var code = fixture.Create <string>(); var fakeRepository = A.Fake <IHotelsRepository>(); A.CallTo(() => fakeRepository.GetBargains(destinationId, nights)).Returns(GetHotels()); var context = new HotelsContext(A.Fake <ILogger <IHotelsContext> >(), fakeRepository); //Act var result = context.GetBargains(destinationId, nights, code); //Assert Assert.That(result.Count, Is.GreaterThan(0)); A.CallTo(() => fakeRepository.GetBargains(A <int> .Ignored, A <int> .Ignored)).MustHaveHappened(); //various data validators }
private Invoice MockInvoiceToDb() { var Context = new HotelsContext(); var testInvoice = new Invoice { Id = 1, ReservationId = 145, ItemId = 1, TotalAmount = 10000, IsPaid = false }; if (Context.Invoices.Find(testInvoice.Id) == null) { Context.Invoices.Add(testInvoice); Context.SaveChanges(); } return(testInvoice); }
private Reservation MockReservationToDb() { var Context = new HotelsContext(); var testReservation = new Reservation { Id = 221, StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(7), GuestId = 11, RoomId = 1, ReservationStatusId = 1 }; if (Context.Reservations.Find(testReservation.Id) == null) { Context.Reservations.Add(testReservation); Context.SaveChanges(); } return(testReservation); }
private Guest MockGuestToDb() { var Context = new HotelsContext(); var testGuest = new Guest { Id = 8, FirstName = "TestingRuskDb", LastName = "TestRussianDb", Address = "TestAddressDb", Email = "*****@*****.**", PhoneNumber = "123456789" }; if (Context.Guests.Find(testGuest.Id) == null) { Context.Guests.Add(testGuest); Context.SaveChanges(); } return(testGuest); }
protected void Page_Load(object sender, System.EventArgs e) { if (Request.Params["logout"] != null) { Response.Cookies["token"].Value = null; Response.Redirect("Login.aspx"); return; } if (!string.IsNullOrEmpty(Output.Text)) { Output.Text = ""; } Register.Click += Register_Click; Submit.Click += Submit_Click; using HotelsContext c = new HotelsContext(); users.AddRange(from u in c.User.AsEnumerable() from r in c.Role.AsEnumerable() where r.Id == u.RoleId select new LoginUser(r.Name, u.Login, u.PasswordHash)); if (Request.Cookies["token"] != null) { foreach (LoginUser u in users) { if (Utils.MakeToken(u.Login, u.PasswordHash) == Request.Cookies["token"].Value) { NewPage(u.Role); return; } } } }
public void TestInit() { _context = Utility.GetDbContext(); _InvoiceItemController = new InvoiceItemController(_context); }
public void TestInit() { _context = Utility.GetDbContext(); _RoomController = new RoomController(_context); }
public void TestInit() { _context = Utility.GetDbContext(); _HotelManagerController = new HotelManagerController(_context); }
public RoomController(HotelsContext context) { _context = context; }
public ReservationController(HotelsContext context) { _context = context; }