// POST shares/update
        public HttpResponseMessage Update([FromBody] ShareInputData value)
        {
            if (value == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            sharesService.ChangeCompanyName(value.Id, value.CompanyName);
            sharesService.ChangeType(value.Id, shareTypesService.GetShareType(value.ShareTypeId));

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
        // POST shares/add
        public HttpResponseMessage Add([FromBody] ShareInputData value)
        {
            if (value == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            var shareId = sharesService.RegisterNewShare(new ShareRegistrationInfo()
            {
                CompanyName = value.CompanyName,
                Type        = shareTypesService.GetShareType(value.ShareTypeId)
            });

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
        public string Run(RequestSender requestSender, ILoggerService log)
        {
            string welcome = "  Edit Share info service";

            log.Info(welcome);
            Console.WriteLine(welcome); // signal about enter into case

            int    id = 0, shareTypeId = 0;
            string companyName = string.Empty;

            string inputString = string.Empty;

            while (inputString != "e")
            {
                if (id == 0)
                {
                    Console.Write("   Enter the Id of share: ");
                    inputString = Console.ReadLine();
                    log.Info($"Id of share input: {inputString}");
                    int inputInt;
                    int.TryParse(inputString, out inputInt);
                    if (!StockExchangeValidation.checkId(inputInt))
                    {
                        continue;
                    }
                    id = inputInt;
                }

                if (string.IsNullOrEmpty(companyName))
                {
                    Console.Write("   Enter the Company name: ");
                    inputString = Console.ReadLine();
                    log.Info($"Company name input: {inputString}");
                    if (!StockExchangeValidation.checkCompanyName(inputString))
                    {
                        continue;
                    }
                    companyName = inputString;
                }

                if (shareTypeId == 0)
                {
                    Console.Write("   Enter the Id of share type: ");
                    inputString = Console.ReadLine();
                    log.Info($"Id of share type input: {inputString}");
                    int inputInt;
                    int.TryParse(inputString, out inputInt);
                    if (!StockExchangeValidation.checkId(inputInt))
                    {
                        continue;
                    }
                    shareTypeId = inputInt;
                }

                break;
            }

            if (inputString == "e")
            {
                string exitString = "Exit from Edit Share info service";
                log.Info(exitString);
                return(exitString);
            }

            Console.WriteLine("    Wait a few seconds, please.");

            var shareInputData = new ShareInputData
            {
                Id          = id,
                CompanyName = companyName,
                ShareTypeId = shareTypeId
            };

            log.Info($"Created ShareInputData with Id = {id}, CompanyName = { companyName}, ShareTypeId = { shareTypeId}");

            var reqResult = requestSender.EditShare(shareInputData);

            log.Info($"Request result: {reqResult}.");
            if (string.IsNullOrWhiteSpace(reqResult))
            {
                return($"Share with Id = {id} was changed! Press Enter.");
            }
            return("Error. Share wasn't changed! Press Enter.");
        }
示例#4
0
        public string EditShare(ShareInputData shareInputData)
        {
            string request = "share/update";

            return(Post <ShareInputData, string>(request, shareInputData));
        }
示例#5
0
        public string AddShare(ShareInputData shareInputData)
        {
            string request = "share/add";

            return(Post <ShareInputData, string>(request, shareInputData));
        }