Exemplo n.º 1
0
        public ActionResult Rent(ClientInstrument clientInstrument)
        {
            // Check if the model is valid
            if (ModelState.IsValid)
            {
                // It's valid
                // Add the client first
                var client = new Client()
                {
                    FirstName    = clientInstrument.Client.FirstName,
                    LastName     = clientInstrument.Client.LastName,
                    Address      = clientInstrument.Client.Address,
                    City         = clientInstrument.Client.City,
                    State        = clientInstrument.Client.State,
                    Zipcode      = clientInstrument.Client.Zipcode,
                    EmailAddress = clientInstrument.Client.EmailAddress,
                    PhoneNumber  = clientInstrument.Client.PhoneNumber
                };

                db.Clients.Add(client);
                db.SaveChanges();

                // Grab the last added clientID
                var clientID = db.Clients.OrderByDescending(x => x.ClientID).FirstOrDefault().ClientID;

                // Now add the instrument
                var instrument = new Instrument()
                {
                    Name     = clientInstrument.Instrument.Name,
                    Price    = clientInstrument.Instrument.Price,
                    New      = clientInstrument.Instrument.New,
                    Location = clientInstrument.Instrument.Location,
                    ClientID = clientID
                };

                db.Instruments.Add(instrument);
                db.SaveChanges();

                // Add the clientInstrument to the tempdata
                clientInstrument.Instrument = instrument;
                clientInstrument.Client     = client;

                TempData["clientInstrument"] = clientInstrument;

                return(RedirectToAction("Summary"));
            }
            else
            {
                // The model isn't valid so send everything back
                return(View("~/Views/ClientInstrument/Create.cshtml", clientInstrument));
            }
        }
Exemplo n.º 2
0
        // This is the summary page
        public ActionResult Summary()
        {
            // Make the clientInstrument from the tempdata
            ClientInstrument clientInstrument = (ClientInstrument)TempData["clientInstrument"];

            // Create the viewbag for the result
            ViewBag.Result = "Thanks, " + clientInstrument.Client.FirstName + " for renting a " +
                             clientInstrument.Instrument.Name + ". Your order number is " + clientInstrument.Instrument.ClientID +
                             ". Your monthly payment is $" + clientInstrument.Instrument.Price + ". The total amount paid" +
                             " after 18 months is $" + (clientInstrument.Instrument.Price * 18) + ".";

            return(View(clientInstrument));
        }
Exemplo n.º 3
0
        public ActionResult Summary(ClientInstrument clientInstrument)
        {
            // Add the location for the picture
            ViewBag.Location = clientInstrument.Instrument.Location;

            // Create the viewbag for the result
            ViewBag.Result = "Thanks, " + clientInstrument.Client.FirstName + " for renting a " +
                             clientInstrument.Instrument.Name + ". Your order number is " + clientInstrument.Client.ClientID +
                             ". Your monthly payment is $" + clientInstrument.Instrument.Price + ". The total amount paid" +
                             " after 18 months is " + (clientInstrument.Instrument.Price * 18) + ".";

            return(View(clientInstrument));
        }
Exemplo n.º 4
0
        public ActionResult Rent(int id)
        {
            // Find the specific instrument
            int index = listOfInstruments.FindIndex(x => x.InstrumentID == id);

            // Create the ClientInstrument model and add the right instrument to it
            ClientInstrument clientInstrument = new ClientInstrument();

            clientInstrument.Instrument = listOfInstruments[index];

            // Create the reference to the right image
            ViewBag.Location = clientInstrument.Instrument.Name + ".jpg";

            // Add the location to the model
            clientInstrument.Instrument.Location = ViewBag.Location;

            // Return the view for the Create clientInstrument form
            return(View("~/Views/ClientInstrument/Create.cshtml", clientInstrument));
        }
Exemplo n.º 5
0
 public static char GetStateOnSymbol(ClientInstrument instr)
 {
     if (instr.InstrumentName == "ADA-USD")
     {
         return(ClientInstrumentState._STATE_CLOSE);
     }
     else if (instr.InstrumentName == "XMR-USD")
     {
         return(ClientInstrumentState._STATE_INACTIVE);
     }
     else if (instr.InstrumentName == "XRP-USD")
     {
         return(ClientInstrumentState._STATE_UNKNOWN);
     }
     else
     {
         return(ClientInstrumentState._STATE_HALT);
     }
 }
Exemplo n.º 6
0
        public ActionResult Create(ClientInstrument clientInstrument)
        {
            // Check if the model is valid
            if (ModelState.IsValid)
            {
                // It's valid
                // Add the client first
                var client = new Client()
                {
                    FirstName    = clientInstrument.Client.FirstName,
                    LastName     = clientInstrument.Client.LastName,
                    Address      = clientInstrument.Client.Address,
                    City         = clientInstrument.Client.City,
                    State        = clientInstrument.Client.State,
                    Zipcode      = clientInstrument.Client.Zipcode,
                    EmailAddress = clientInstrument.Client.EmailAddress,
                    PhoneNumber  = clientInstrument.Client.PhoneNumber
                };

                db.Clients.Add(client);
                db.SaveChanges();

                // Now add the instrument
                var instrument = new Instrument()
                {
                    Name     = clientInstrument.Instrument.Name,
                    Price    = clientInstrument.Instrument.Price,
                    New      = clientInstrument.Instrument.New,
                    Location = clientInstrument.Instrument.Location,
                    ClientID = (int)client.ClientID
                };

                db.Instruments.Add(instrument);
                db.SaveChanges();
                return(View("Summary", clientInstrument));
            }
            else
            {
                // The model isn't valid so send everything back
                return(View(clientInstrument));
            }
        }
Exemplo n.º 7
0
        public static ClientInstrument GetInstrumentByIntInstrumentId(ClientInstrumentBatch InstrBatch, string instrumentId)
        {
            ClientInstrument instr = InstrBatch.messages.Where(x => x.InstrumentId == instrumentId).FirstOrDefault();

            return(instr);
        }
Exemplo n.º 8
0
        public override async void ReadResponses(object param)
        {
            while (true)
            {
                try
                {
                    string resp = "";
                    WebSocketReceiveResult webSocketResp;
                    if (SubscriptionWebSocket.State == WebSocketState.Open)
                    {
                        do
                        {
                            ArraySegment <byte> bytesReceived = new ArraySegment <byte>(new byte[1000]);
                            webSocketResp = await SubscriptionWebSocket.ReceiveAsync(bytesReceived, CancellationToken.None);

                            resp += Encoding.ASCII.GetString(bytesReceived.Array, 0, webSocketResp.Count);
                        }while (!webSocketResp.EndOfMessage);

                        if (resp != "")
                        {
                            WebSocketMessageV2 wsResp = JsonConvert.DeserializeObject <WebSocketMessageV2>(resp);

                            if (wsResp.Msg == "ClientLoginResponse")
                            {
                                ClientLoginResponse loginReponse = JsonConvert.DeserializeObject <ClientLoginResponse>(resp);
                                OnEvent(loginReponse);
                            }

                            else if (wsResp.Msg == "ClientLogout")
                            {
                                ClientLogout logoutReponse = JsonConvert.DeserializeObject <ClientLogout>(resp);
                                OnEvent(logoutReponse);
                            }
                            else if (wsResp.Msg == "ClientLogout")
                            {
                                ClientOrderAck clientOrderAck = JsonConvert.DeserializeObject <ClientOrderAck>(resp);
                                OnEvent(clientOrderAck);
                            }
                            else if (wsResp.Msg == "ClientOrderRej")
                            {
                                ClientOrderRej clientOrderRej = JsonConvert.DeserializeObject <ClientOrderRej>(resp);
                                OnEvent(clientOrderRej);
                            }
                            else if (wsResp.Msg == "TokenResponse")
                            {
                                TokenResponse tokenReponse = JsonConvert.DeserializeObject <TokenResponse>(resp);
                                OnEvent(tokenReponse);
                            }
                            else if (wsResp.Msg == "SubscriptionResponse")
                            {
                                SubscriptionResponse msg = JsonConvert.DeserializeObject <SubscriptionResponse>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "ClientAccountRecord")
                            {
                                ClientAccountRecord msg = JsonConvert.DeserializeObject <ClientAccountRecord>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "ClientLastSale")
                            {
                                ClientLastSale msg = JsonConvert.DeserializeObject <ClientLastSale>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "ClientBestBidOffer")
                            {
                                ClientBestBidOffer msg = JsonConvert.DeserializeObject <ClientBestBidOffer>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "ClientMarketState")
                            {
                                ClientMarketState msg = JsonConvert.DeserializeObject <ClientMarketState>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "ClientInstrument")
                            {
                                ClientInstrument msg = JsonConvert.DeserializeObject <ClientInstrument>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "DailySettlementPrice")
                            {
                                ClientDSP msg = JsonConvert.DeserializeObject <ClientDSP>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "ClientOrderAck")
                            {
                                ClientOrderAck msg = JsonConvert.DeserializeObject <ClientOrderAck>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "ClientOrderRej")
                            {
                                ClientOrderRej msg = JsonConvert.DeserializeObject <ClientOrderRej>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "ClientOrderReq")
                            {
                                ClientOrderReq msg = JsonConvert.DeserializeObject <ClientOrderReq>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "FirmsCreditLimitUpdateResponse")
                            {
                                FirmsCreditLimitUpdateResponse msg = JsonConvert.DeserializeObject <FirmsCreditLimitUpdateResponse>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "FirmsTradingStatusUpdateResponse")
                            {
                                FirmsTradingStatusUpdateResponse msg = JsonConvert.DeserializeObject <FirmsTradingStatusUpdateResponse>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "EmailNotificationsListResponse")
                            {
                                EmailNotificationsListResponse msg = JsonConvert.DeserializeObject <EmailNotificationsListResponse>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "EmailNotificationsCreateResponse")
                            {
                                EmailNotificationsCreateResponse msg = JsonConvert.DeserializeObject <EmailNotificationsCreateResponse>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "EmailNotificationsUpdateResponse")
                            {
                                EmailNotificationsUpdateResponse msg = JsonConvert.DeserializeObject <EmailNotificationsUpdateResponse>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "EmailNotificationsDeleteResponse")
                            {
                                EmailNotificationsDeleteResponse msg = JsonConvert.DeserializeObject <EmailNotificationsDeleteResponse>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "FirmsListResponse")
                            {
                                FirmsListResponse msg = JsonConvert.DeserializeObject <FirmsListResponse>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "ClientMassCancelResponse")
                            {
                                ClientMassCancelResponse msg = JsonConvert.DeserializeObject <ClientMassCancelResponse>(resp);
                                OnEvent(msg);
                            }
                            else if (wsResp.Msg == "ClientHeartbeat")
                            {
                                OnEvent(JsonConvert.DeserializeObject <ClientHeartbeat>(resp));
                            }
                            else
                            {
                                UnknownMessageV2 unknownMsg = new UnknownMessageV2()
                                {
                                    Msg    = "UnknownMsg",
                                    Resp   = resp,
                                    Reason = string.Format("Unknown message: {0}", resp)
                                };
                                OnEvent(unknownMsg);
                            }
                        }
                    }
                    else
                    {
                        Thread.Sleep(1000);
                    }
                }
                catch (Exception ex)
                {
                    ErrorMessageV2 errorMsg = new ErrorMessageV2()
                    {
                        Msg = "ErrorMsg", Error = ex.Message
                    };
                    OnEvent(errorMsg);
                }
            }
        }