Пример #1
0
        public override Task <Response> AddBooking(Request request, ServerCallContext context)
        {
            Logger.Info("add booking");
            Response response = null;

            try
            {
                tripsGrpc.Booking booking = request.Booking;
                Trip    trip         = ProtoUtils.ConvertToTrip(booking.Trip);
                Account account      = ProtoUtils.ConvertToAccount(booking.Account);
                Booking savedBooking = tripServices.AddBooking(booking.Client, booking.Phone, booking.NumTickets, trip, account);
                response = ProtoUtils.CreateOkResponse();

                Logger.Info("notifying observers");
                Response responseBookingAdded = new Response()
                {
                    Booking = new tripsGrpc.Booking()
                    {
                        Id         = savedBooking.Id,
                        Account    = booking.Account,
                        Trip       = booking.Trip,
                        Client     = savedBooking.ClientName,
                        Phone      = savedBooking.PhoneNumber,
                        NumTickets = savedBooking.NumTickets
                    }
                };
                buffer.Post(responseBookingAdded);
            }
            catch (Exception e)
            {
                response = ProtoUtils.CreateErrorResponse(e);
            }
            Logger.InfoFormat("add booking response {0}", response);
            return(Task.FromResult(response));
        }
Пример #2
0
        public static Response CreateLoginResponse(Account account)
        {
            Response response = null;

            if (account == null)
            {
                response = new Response()
                {
                    Type  = Response.Types.ResponseType.Error,
                    Error = "Invalid name or password"
                };
            }
            else
            {
                AccountDto a = new AccountDto()
                {
                    Id       = account.Id,
                    Name     = account.Name,
                    Password = account.Password
                };
                response = new Response()
                {
                    Type    = Response.Types.ResponseType.Ok,
                    Account = a
                };
            }
            return(response);
        }
Пример #3
0
        public override Task <Response> GetAccountByNamePassword(Request request, ServerCallContext context)
        {
            Account a = ProtoUtils.GetAccount(request);

            Logger.InfoFormat("getting account by name {0} and password {1}", a.Name, a.Password);
            Response response = null;

            try
            {
                Account account = tripServices.GetAccountByNamePassword(a.Name, a.Password);
                response = ProtoUtils.CreateLoginResponse(account);
            }
            catch (Exception e)
            {
                response = ProtoUtils.CreateErrorResponse(e);
            }
            Logger.InfoFormat("sending response {0}", response);
            return(Task.FromResult(response));
        }