public GetUserListResponseDTO GetUsers(GetUserRequestDTO request) { var users = uow.User.GetUsers(request.UserID, request.UserName, request.Name, request.SurName, request.Email); var result = Imapper.Map <GetUserListResponseDTO>(users); return(result); }
public List <Message> getMessagesByReservation(long reservationId) { getMessagesByReservationRequest getMessagesByReservationRequest = new getMessagesByReservationRequest() { id = reservationId }; GetMessagesByReservationResponseDTO responseDTO = new GetMessagesByReservationResponseDTO(messagePortClient.getMessagesByReservation(getMessagesByReservationRequest)); foreach (Message message in responseDTO.Messages) { List <User> users = new List <User>(); if (message.Receiver != null) { users.Add(message.Receiver); } users.Add(message.Sender); //modificate sender and reciever in local DB foreach (User user in users) { GetUserRequestDTO getUserRequestDTO = new GetUserRequestDTO(user.Username); GetUserResponseDTO getUserResponseDTO = new GetUserResponseDTO(userPortClient.getUsers(getUserRequestDTO.GetUsersRequest), user.Username); User newUser = getUserResponseDTO.User; addressService.updateAddress(newUser.Address); User userDB = unitOfWork.Users.SingleOrDefault(u => u.Id == user.Id); if (userDB != null) { //update user in local DB //userDB = newUser; System.Console.WriteLine("postoji vec user!"); userDB.Name = newUser.Name; userDB.LastName = newUser.LastName; userDB.Password = newUser.Password; userDB.Blocked = newUser.Blocked; userDB.Deleted = newUser.Deleted; userDB.Address = unitOfWork.Addresses.SingleOrDefault(a => a.Id == newUser.Address.Id); } else { unitOfWork.Users.Add(newUser); } unitOfWork.Complete(); } Message messageDB = unitOfWork.Messages.SingleOrDefault(m => m.Id == message.Id); if (messageDB != null) { if (message.Receiver != null) { messageDB.Receiver = unitOfWork.Users.SingleOrDefault(u => u.Id == message.Receiver.Id); } messageDB.Seen = message.Seen; } else { message.Sender = unitOfWork.Users.SingleOrDefault(u => u.Id == message.Sender.Id); if (message.Receiver != null) { message.Receiver = unitOfWork.Users.SingleOrDefault(u => u.Id == message.Receiver.Id); } message.Reservation = unitOfWork.Reservations.Get(message.Reservation.Id); unitOfWork.Messages.Add(message); } unitOfWork.Complete(); } return(unitOfWork.Messages.Find(m => m.Reservation.Id == reservationId).ToList()); }
public List <Reservation> GetReservations(long accommodationUnitId, long accommodationId) { if (accommodationUnitId == 0) { List <AccommodationUnit> accommodationUnits = unitOfWork.AccommodationUnits.Find(u => u.Accommodation.Id == accommodationId).ToList(); foreach (AccommodationUnit unit in accommodationUnits) { GetUnitReservationsRequestDTO getUnitReservationsRequestDTO = new GetUnitReservationsRequestDTO(unit.Id); try { GetUnitReservationsResponseDTO getUnitReservationsResponseDTO = new GetUnitReservationsResponseDTO(reservationPortClient.getReservationsByUnit(getUnitReservationsRequestDTO.GetReservationsByUnitRequest)); if (getUnitReservationsResponseDTO.Reservations.Count > 0) { foreach (Reservation reservation in getUnitReservationsResponseDTO.Reservations) { GetUserRequestDTO getUserRequestDTO = new GetUserRequestDTO(reservation.Guest.Username); GetUserResponseDTO getUserResponseDTO = new GetUserResponseDTO(userPortClient.getUsers(getUserRequestDTO.GetUsersRequest), reservation.Guest.Username); //first add user in local DB and then set it as guest in reservation User user = getUserResponseDTO.User; User userDB = unitOfWork.Users.SingleOrDefault(u => u.Id == user.Id); if (userDB != null) { //update user in local DB userDB = user; userDB.Name = user.Name; userDB.LastName = user.LastName; userDB.Password = user.Password; userDB.Blocked = user.Blocked; userDB.Deleted = user.Deleted; } else { unitOfWork.Users.Add(user); } unitOfWork.Complete(); //add reservation in local DB Reservation reservationDB = unitOfWork.Reservations.SingleOrDefault(r => r.Id == reservation.Id); if (reservationDB != null) { //update reservation in local DB if (reservationDB.CommentRate == null) { reservationDB.CommentRate = reservation.CommentRate; } else { reservationDB.CommentRate.ApprovedComment = reservation.CommentRate.ApprovedComment; } reservationDB.Confirmed = reservation.Confirmed; reservationDB.FromDate = reservation.FromDate; reservationDB.ToDate = reservation.ToDate; reservationDB.AgentConfirmed = reservation.AgentConfirmed; reservationDB.Price = reservation.Price; } else { reservation.AccommodationUnit = unitOfWork.AccommodationUnits.Get(getUnitReservationsResponseDTO.UnitId); reservation.Guest = unitOfWork.Users.SingleOrDefault(u => u.Username == reservation.Guest.Username); unitOfWork.Reservations.Add(reservation); } unitOfWork.Complete(); } } List <Reservation> unitReservations = unitOfWork.Reservations.Find(r => r.AccommodationUnit.Id == unit.Id).ToList(); //set reservation delete in localDB foreach (Reservation reservation in unitReservations) { int flag = 0; foreach (Reservation r in getUnitReservationsResponseDTO.Reservations) { if (r.Id == reservation.Id) { flag += 1; } } if (flag == 0) { Reservation rDB = unitOfWork.Reservations.Get(reservation.Id); rDB.Deleted = true; unitOfWork.Complete(); } } } catch { } } return(unitOfWork.Reservations.Find(r => r.AccommodationUnit.Accommodation.Id == accommodationId && r.Deleted == false).ToList()); } else { return(unitOfWork.Reservations.Find(r => r.AccommodationUnit.Id == accommodationUnitId && r.Deleted == false).ToList()); } }
public GetUserListResponseDTO GetUsers(GetUserRequestDTO request) { return(AuthenticationService.GetUsers(request)); }