public IActionResult Post(CreateCustomerDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ReadCustomerDto readDto = new ReadCustomerDto(); try { _repository.BeginTransaction(); var customer = _mapper.Map <Customer>(model); //customer.DateCreated = DateTime.Now; _repository.createCustomer(customer); _repository.saveChanges(); _repository.CommitTransaction(); readDto = _mapper.Map <ReadCustomerDto>(customer); } catch (Exception ex) { _repository.RollBackTransaction(); throw new ApiException(ex.Message, 400); } return(Ok(readDto)); }
public IActionResult Post(CreateReservationDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ReservationReadDto readDto = new ReservationReadDto(); try { //mark room as booked //might want to differientiate online and admin end points but //use the same implementation // online user's reservation room should still be free until they make payment //perphaps there should be a setup that tell us how long an online room should //remain booked before successful transaction is confirmed. _repository.BeginTransaction(); var reservation = _mapper.Map <Reservation>(model); // reservation.DateCreated = DateTime.Now; reservation.ReservationDate = DateTime.Now; _repository.updateRoomStatus(reservation.RoomId, RoomStatusEnum.BookedPaid); _repository.createReservation(reservation); _repository.saveChanges(); _repository.CommitTransaction(); readDto = _mapper.Map <ReservationReadDto>(reservation); } catch (Exception ex) { _repository.RollBackTransaction(); throw new ApiException(ex.Message, 400); } return(Ok(readDto)); }
public IActionResult Post(RoomTypeCreateDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } RoomTypeReadDto readRoomType = new RoomTypeReadDto(); _repository.BeginTransaction(); try { var room = _Mapper.Map <RoomType>(model); _repository.createRoomType(room); _repository.saveChanges(); _repository.CommitTransaction(); readRoomType = _Mapper.Map <RoomTypeReadDto>(room); } catch (Exception ex) { _repository.RollBackTransaction(); throw new ApiException(ex.Message, 400); } return(Ok(readRoomType)); }
public IActionResult Post(RoomCreateDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var isRoomExits = _repository.getRoom(model.RoomNo); if (isRoomExits != null) { return(BadRequest("Room Number Already Exists")); } RoomReadDto readRoom = new RoomReadDto(); _repository.BeginTransaction(); try { var room = _Mapper.Map <Room>(model); _repository.createRoom(room); _repository.saveChanges(); _repository.CommitTransaction(); readRoom = _Mapper.Map <RoomReadDto>(room); } catch (Exception ex) { _repository.RollBackTransaction(); throw new ApiException(ex.Message, 400); } return(Ok(readRoom)); }
public ActionResult <ReadUserDto> Post(CreateUserDto createUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ReadUserDto readUser = new ReadUserDto(); try { _repository.BeginTransaction(); Guid genUserId = Guid.NewGuid(); var userModel = _mapper.Map <User>(createUser); //userModel.DateCreated = DateTime.Now; //userModel.UserId = Guid.NewGuid().ToString("N"); _repository.createUser(userModel); _repository.saveChanges(); readUser = _mapper.Map <ReadUserDto>(userModel); // throw new Exception("Something Went Wrong"); _repository.CommitTransaction(); } catch (Exception ex) { _repository.RollBackTransaction(); throw new ApiException(ex.Message); } return(readUser); }