public IActionResult PutReview(long id, [FromBody] Review review) { if (id != review.Id) { return(BadRequest()); } _context.Entry(review).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ReviewExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public Reservation Create(ReservationPostModel reservation) { Reservation reservationToAdd = ReservationPostModel.PostReservationModel(reservation); context.Reservations.Add(reservationToAdd); context.SaveChanges(); return(reservationToAdd); }
public void PostRegister(Booking booking) { using (var db = new BookingsDbContext()) { var checkin = db.Bookings.Add(booking); db.SaveChanges(); } }
public User AuthenticateFacebook(User userdata) { var alreadySaved = _dbContext.Users.Where(x => x.Token == userdata.Token).FirstOrDefault(); if (alreadySaved != null) { return(alreadySaved); } var user = new User { Id = userdata.Id, FirstName = userdata.FirstName, LastName = userdata.LastName, Email = userdata.Email, PictureURL = userdata.PictureURL, Role = "User" // by default every user that signs-in with FB has User role }; // generez propriul jwt token si nu folosesc token de la FB // authentication successful so generate jwt token var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_appSettings.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.Id.ToString()), new Claim(ClaimTypes.Role, user.Role) }), Expires = DateTime.UtcNow.AddDays(7), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); user.Token = tokenHandler.WriteToken(token); _dbContext.Users.Add(user); _dbContext.SaveChanges(); // authentication successful return(user); //user.WithoutPassword(); }
public Models.Registration GetCheckout(int registrationId) { using (var db = new BookingsDbContext()) { db.Bookings.Single(b => b.Id == registrationId).Type = "CheckIn"; db.SaveChanges(); return(ConvertToRegistration(db.Bookings.Single(b => b.Id == registrationId))); } }
public void Setup() { //orgranisation table setup organisation = new Organisation("strawhat"); //persons record IndividualPerson = new Person("mr", "luffy", "dragon", "*****@*****.**") { ContactEmail = "*****@*****.**", Organisation = organisation }; JudgePerson = new Person("mr", "zoro", "rononora", "*****@*****.**") { ContactEmail = "*****@*****.**", Organisation = organisation }; JudicialOfficeHolderPerson = new Person("mr", "luffy", "dragon", "*****@*****.**") { ContactEmail = "*****@*****.**", Organisation = organisation }; StaffMemberPerson = new Person("mr", "luffy", "duffy", "*****@*****.**") { ContactEmail = "*****@*****.**", Organisation = organisation }; //participants record IndividualParticipant = new Individual(IndividualPerson, new HearingRole(123, "hearingrole"), new CaseRole(345, "caserole")) { Discriminator = "Individual" }; var IndividualParticipant2 = new Individual(IndividualPerson, new HearingRole(123, "hearingrole"), new CaseRole(345, "caserole")) { Discriminator = "Individual" }; JudgeParticipant = new Judge(JudgePerson, new HearingRole(123, "hearingrole"), new CaseRole(345, "caserole")) { Discriminator = "Judge" }; JudicialOfficeHolderParticipant = new JudicialOfficeHolder(JudicialOfficeHolderPerson, new HearingRole(123, "hearingrole"), new CaseRole(345, "caserole")) { Discriminator = "JudicialOfficeHolder" }; StaffMemberParticipant = new JudicialOfficeHolder(StaffMemberPerson, new HearingRole(719, "hearingrole"), new CaseRole(345, "caserole")) { Discriminator = "StaffMember" }; _context.Persons.AddRange(IndividualPerson, JudgePerson, JudicialOfficeHolderPerson, StaffMemberPerson); _context.Participants.AddRange(IndividualParticipant, IndividualParticipant2, JudgeParticipant, JudicialOfficeHolderParticipant, StaffMemberParticipant); _context.SaveChanges(); _configOptions.Setup(opt => opt.Value).Returns(new FeatureFlagConfiguration() { EJudFeature = true }); _handler = new GetPersonBySearchTermQueryHandler(_context, _configOptions.Object); }
public static void Initialize(BookingsDbContext context) { if (context.Users.Count() > 4) // la momentul seed-ului am 3 inregistrari in DB, de-asta 3 { return; } context.Users.AddRange( new User { FirstName = "Admin", LastName = "Admin", Username = "******", PasswordHash = SHA512("admin"), PasswordSalt = SaltedPassword("admin", "admin"), Role = Role.Admin }, new User { FirstName = "Anda", LastName = "Murarescu", Username = "******", PasswordHash = SHA512("anda"), PasswordSalt = SaltedPassword("anda", "anda"), Role = Role.User } ); if (context.Hotels.Count() >= 50) { return; } for (int i = 1; i <= 50; ++i) { context.Hotels.Add( new Hotel { HotelName = $"Hotel-{i}", City = $"City-{i}", Capacity = i, Rating = i } ); context.SaveChanges(); } }
public void Setup() { _organisation = new Organisation(Faker.Company.Name()); _individualPerson = new Person(Faker.Name.Suffix(), Faker.Name.First(), Faker.Name.Last(), Faker.Internet.Email()) { ContactEmail = Faker.Internet.Email(), Organisation = _organisation }; _judgePerson = new Person(Faker.Name.Suffix(), Faker.Name.First(), Faker.Name.Last(), Faker.Internet.Email()) { ContactEmail = Faker.Internet.Email(), Organisation = _organisation }; _judicialOfficeHolderPerson = new Person(Faker.Name.Suffix(), Faker.Name.First(), Faker.Name.Last(), Faker.Internet.Email()) { ContactEmail = Faker.Internet.Email(), Organisation = _organisation }; _staffMemberPerson = new Person(Faker.Name.Suffix(), Faker.Name.First(), Faker.Name.Last(), Faker.Internet.Email()) { ContactEmail = Faker.Internet.Email(), Organisation = _organisation }; _repPerson = new Person(Faker.Name.Suffix(), Faker.Name.First(), Faker.Name.Last(), Faker.Internet.Email()) { ContactEmail = Faker.Internet.Email(), Organisation = _organisation }; _judgeParticipant = new Judge(_judgePerson, new HearingRole(123, "hearingrole"), new CaseRole(345, "caserole")) { Discriminator = "Judge" }; _individualParticipant = new Individual(_individualPerson, new HearingRole(123, "hearingrole"), new CaseRole(345, "caserole")) { Discriminator = "Individual" }; _judicialOfficeHolderParticipant = new JudicialOfficeHolder(_judicialOfficeHolderPerson, new HearingRole(123, "hearingrole"), new CaseRole(345, "caserole")) { Discriminator = "JudicialOfficeHolder" }; _staffMemberParticipant = new JudicialOfficeHolder(_staffMemberPerson, new HearingRole(719, "hearingrole"), new CaseRole(345, "caserole")) { Discriminator = "StaffMember" }; _repParticipant = new JudicialOfficeHolder(_repPerson, new HearingRole(719, "hearingrole"), new CaseRole(345, "caserole")) { Discriminator = "Representative" }; _context.Persons.AddRange(_individualPerson, _judgePerson, _judicialOfficeHolderPerson, _staffMemberPerson); _context.Participants.AddRange(_individualParticipant, _judgeParticipant, _judicialOfficeHolderParticipant, _staffMemberParticipant, _repParticipant); _context.SaveChanges(); _handler = new GetStaffMemberBySearchTermQueryHandler(_context); }
public void PostCheckin(int registrationId) { using (var db = new BookingsDbContext()) { var booking = db.Bookings .Where(b => b.Id == registrationId) .First(); booking.From = DateTime.Today.AddHours(-1); booking.To = DateTime.Today; db.SaveChanges(); } }
public void PostRegister(Booking booking) { using (var db = new BookingsDbContext()) { var checkin = db.Bookings.Add(booking); db.SaveChanges(); } var isStoreKPIEnabled = Environment.GetEnvironmentVariable("UseStoreKPIsStatefulService"); if (isStoreKPIEnabled == bool.TrueString) { UpdateRegistrationKPIStatefulService(booking); } }
//public Movie Create(Movie movieToAdd) //{ // // TODO: how to store the user that added the movie as a field in Movie? // context.Movies.Add(movieToAdd); // context.SaveChanges(); // return movieToAdd; //} public Hotel Create(Hotel hotel) { context.Hotels.Add(hotel); context.SaveChanges(); return(hotel); }