public async Task <ActionResult <Cabin> > PostCabin([FromBody] Cabin cabin) { _context.Cabin.Add(cabin); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCabin), new { id = cabin.Id }, cabin)); }
public async Task <IActionResult> Create(Reservation reservation) { if (ModelState.IsValid) { var type = _res.ReservationTypes.Where(r => r.Id == reservation.ReservationType.name).FirstOrDefault(); var student = await _userManager.GetUserAsync(HttpContext.User); var reser = new Reservation(); reser.Status = reservation.Status; reser.Date = reservation.Date; reser.Cause = reservation.Cause; reser.StudentId = student.Id; reser.ReservationTypeId = type.Id; _res.Add(reser); await _res.SaveChangesAsync(); _toastNotification.AddSuccessToastMessage("You reserve your place successfully"); return(RedirectToAction("index")); } return(View(reservation)); }
public async Task <ActionResult <Service> > PostService([FromBody] Service service) { _context.Service.Add(service); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetService), new { id = service.Id }, service)); }
public async Task <IHttpActionResult> PutReservations(int id, Reservations reservations) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != reservations.ReservationID) { return(BadRequest()); } db.Entry(reservations).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReservationsExists(id)) { return(NotFound()); } else { throw; } } return(Ok(reservations)); }
public async Task <IActionResult> PutReservation(int id, Reservation reservation) { _logger.LogInformation(nameof(PutReservation) + "(1) - Invoked..."); if (id != reservation.ReservationID) { return(BadRequest()); } _context.Entry(reservation).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReservationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCustomer(int id, [FromBody] Customer customer) { if (id != customer.Id) { return(BadRequest()); } _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutInvoice(int id, [FromBody] Invoice invoice) { if (id != invoice.Id) { return(BadRequest()); } _context.Entry(invoice).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InvoiceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutReservation(int id, Reservation reservation) { if (id != reservation.Id) { return(BadRequest()); } _context.Entry(reservation).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReservationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
// PUT api/Countries/5 public async Task <IHttpActionResult> PutCountry(int id, Country country) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != country.Id) { return(BadRequest()); } db.Entry(country).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CountryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <ActionResult <Resort> > PostResort([FromBody] Resort resort) { _context.Resort.Add(resort); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetResort), new { id = resort.Id }, resort)); }
public async Task <T> AddAsync(T entity) { _dbContext.Set <T>().Add(entity); await _dbContext.SaveChangesAsync(); return(entity); }
public async Task <Reservation> Post([FromBody] Reservation res) { await ReservationContext.Reservations.AddAsync(res); await ReservationContext.SaveChangesAsync(); return(await ReservationContext.Reservations.FindAsync(res.ReservationId)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Date,Time,SeatNumber,Details")] ReservationModel reservationModel) { if (ModelState.IsValid) { _context.Add(reservationModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(reservationModel)); }
public async Task Add(List <Reservation> entities) { foreach (var entity in entities) { entity.Id = Guid.NewGuid().ToString(); _reservationContext.Reservations.Add(entity); } await _reservationContext.SaveChangesAsync(); }
public async Task SeedAsync(ReservationContext context, IHostEnvironment env) { using (context) { if (!context.Offices.Any()) { context.Offices.AddRange( new Office("Amsterdam", new TimeSpan(08, 30, 00), new TimeSpan(17, 00, 00)) { Id = 1 }, new Office("Berlin", new TimeSpan(08, 30, 00), new TimeSpan(20, 00, 00)) { Id = 2 } ); await context.SaveChangesAsync(); } if (!context.MeetingRooms.Any()) { context.MeetingRooms.AddRange( new MeetingRoom("101", 10, 1, 10) { Id = 1 }, new MeetingRoom("102", 20, 1, 20) { Id = 2 }, new MeetingRoom("103", 10, 1, 0) { Id = 3 }, new MeetingRoom("201", 10, 1, 10) { Id = 4 }, new MeetingRoom("202", 20, 1, 20) { Id = 5 }, new MeetingRoom("203", 10, 1, 0) { Id = 6 } ); await context.SaveChangesAsync(); } ; } }
public async Task <ActionResult <Reservation> > CreateReservation(Reservation reservation) { var errorMessage = await isValid(reservation); if (errorMessage != null) { return(BadRequest(errorMessage)); } await _reservationContext.Reservations.AddAsync(reservation); await _reservationContext.SaveChangesAsync(); return(CreatedAtAction(nameof(CreateReservation), reservation)); }
public async Task <IActionResult> Create([FromBody] UserModel model) { using (var context = new ReservationContext()) { if (await context.User.AnyAsync(x => x.Email == model.Email)) { return(Conflict()); } var dbModel = new User() { Email = model.Email, Name = model.Name, Password = model.Password.HashAsSha256(), Type = model.Type }; await context.User.AddAsync(dbModel); await context.SaveChangesAsync(); return(Ok(new UserModelWithId() { Id = dbModel.Id, Name = dbModel.Name, Email = dbModel.Email, Password = String.Empty, Type = dbModel.Type })); } }
public async Task <ActionResult <ReservationItem> > PostReservationItem(ReservationItem item) { _context.ReservationItems.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetReservationItem), new { id = item.Id }, item)); }
public async Task <DbStatusCode> Delete(User entity) { var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(entity.Password); var convertedPassword = System.Convert.ToBase64String(plainTextBytes); var user = await _userContext.Users.FirstOrDefaultAsync(usr => usr.Password == convertedPassword && (usr.Username == entity.Username || usr.Email == entity.Email)); if (user != null) { _userContext.Remove(user); var reservations = await _reservationContext.Reservations.Where(res => res.UserId == user.Id).ToListAsync(); _reservationContext.Reservations.RemoveRange(reservations); await _userContext.SaveChangesAsync(); await _reservationContext.SaveChangesAsync(); return(DbStatusCode.Executed); } return(DbStatusCode.PasswordDoesntMatch); }
public async Task <IActionResult> Update([FromBody] UserModelWithId model) { using (var context = new ReservationContext()) { var user = await context.User.SingleOrDefaultAsync(x => x.Id == model.Id); if (user == null) { return(NotFound()); } if (await context.User.AnyAsync(x => x.Email == user.Email)) { return(BadRequest("Email already used.")); } user.Name = model.Name; user.Email = model.Email; user.Type = model.Type; if (string.IsNullOrWhiteSpace(model.Password) == false) { user.Password = model.Password.HashAsSha256(); } model.Password = string.Empty; await context.SaveChangesAsync(); } return(Ok(model)); }
public async Task <IActionResult> Reserve(int locationId, DateTime dateTime, string deviceId) { using (var context = new ReservationContext()) { var location = await context.Location.FirstOrDefaultAsync(x => x.Id == locationId); if (location == null) { return(NotFound(nameof(deviceId))); } if (await IsReservationAllowedAsync(context, locationId, dateTime) == false) { return(BadRequest("Error: Reservation not allowed.")); } var humanReadableToken = _humanReadableKeyGeneratorService.GetHumanReadableText(); var reservationToken = Guid.NewGuid().ToString(); (location.Reservations ??= new List <Reservation>()).Add(new Reservation { DeviceId = deviceId, StartTime = dateTime, HumanReadableToken = humanReadableToken, ReservationToken = reservationToken }); await context.SaveChangesAsync(); return(Ok(new CreateReservationResult() { HumanReadableToken = humanReadableToken, ReservationToken = reservationToken })); } }
public async Task <List <object> > PostXmlExtractorAsync([FromBody] string value) { var extractionHelper = new ExtractionHelper.ExtractionHelper(value); List <IItem> items = extractionHelper.extractAsync(); List <object> created_objects = new List <object>(); foreach (IItem item in items) { if (item.ItemType == ItemType.Expense) { ExpenseContext.ExpenseItems.Add((ExpenseItem)item); await ExpenseContext.SaveChangesAsync(); CreatedAtActionResult expense_create = CreatedAtAction(nameof(ExpenseController.GetExpenseItem), new { id = item.Id }, item); created_objects.Add(expense_create.Value); } if (item.ItemType == ItemType.Reservation) { ReservationContext.ReservationItems.Add((ReservationItem)item); await ReservationContext.SaveChangesAsync(); CreatedAtActionResult reserv_create = CreatedAtAction(nameof(ReservationController.GetReservationItem), new { id = item.Id }, item); created_objects.Add(reserv_create.Value); } } return(created_objects); }
public async Task <ActionResult <Room> > CreateRoom([FromBody] Room room) { _db.Rooms.Add(room); await _db.SaveChangesAsync(); return(CreatedAtAction( nameof(GetRoom), new { id = room.RoomId }, room)); }
public async Task <IActionResult> New([Bind("ReservationId,FirstName,LastName,PassportNumber,CellphoneNumber")] Reservation reservation) { if (ModelState.IsValid) { if (reservation.ReservationId == 0) { _context.Add(reservation); } else { _context.Update(reservation); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(reservation)); }
public async Task <ActionResult <Person> > CreatePerson([FromBody] Person person) { _db.Persons.Add(person); await _db.SaveChangesAsync(); return(CreatedAtAction( nameof(GetPerson), new { id = person.PersonId }, person)); }
public async Task <IActionResult> PutContact(int id, ContactCreateDTO contactCreateDTO) { if (!ContactExists(id)) { return(BadRequest()); } var contactType = ContactTypeExists(contactCreateDTO.ContactType); if (contactType == null) { return(BadRequest()); } var contact = new Contact { Id = id, Name = contactCreateDTO.Name, Birthdate = contactCreateDTO.Birthdate, ContactType = contactCreateDTO.ContactType, Phone = contactCreateDTO.Phone, UpdatedAt = DateTime.UtcNow }; _context.Entry(contact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return(NotFound()); } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Date,Time,SeatNumber,Details")] ReservationModel reservationModel) { if (ModelState.IsValid) { _context.Add(reservationModel); await _context.SaveChangesAsync(); await busControl.Publish(new ReservationCreated() { Id = reservationModel.Id, FirstName = reservationModel.FirstName, LastName = reservationModel.LastName, Date = reservationModel.Date, Time = reservationModel.Time, SeatNumber = reservationModel.SeatNumber, Details = reservationModel.Details }); return(RedirectToAction(nameof(Create))); } return(View(reservationModel)); }
public async Task <IActionResult> PutReservation(int id, ReservationCreateDTO reservationDTO) { if (!ReservationExists(id)) { return(NotFound()); } var reservation = DTOCreateToReservation(reservationDTO); reservation.Id = id; reservation.UpdatedAt = DateTime.UtcNow; _context.Entry(reservation).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(BadRequest()); } return(NoContent()); }
public async Task <IActionResult> PutContactType(int id, ContactTypeCreateDTO contactTypeCreateDTO) { if (!ContactTypeExists(id)) { return(NotFound()); } var contactType = new ContactType { Id = id, Description = contactTypeCreateDTO.Description, UpdatedAt = DateTime.UtcNow }; _context.Entry(contactType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(BadRequest()); } return(NoContent()); }
public async Task Delete(int id) { using (var context = new ReservationContext()) { var user = await context.User.SingleOrDefaultAsync(x => x.Id == id); if (user == null) { NotFound(); return; } context.User.Remove(user); await context.SaveChangesAsync(); Ok(); } }