public ActionResult <FinancialEntry> Show(string id)
        {
            FinancialEntry financialEntry = _repository.Get(id);

            if (financialEntry == null)
            {
                return(NotFound());
            }

            return(Ok(financialEntry));
        }
        public ActionResult <FinancialEntry> Update(
            string id,
            [FromBody] FinancialEntry financialEntry)
        {
            var cannotUpdateReason = _repository.GetCannotStoreReason(financialEntry);

            if (cannotUpdateReason != null)
            {
                return(UnprocessableEntity(cannotUpdateReason.GetCause()));
            }

            financialEntry.Id = id;
            return(Ok(_repository.Update(financialEntry)));
        }
        public ActionResult <FinancialEntry> Store(
            [FromBody] FinancialEntry financialEntry)
        {
            var cannotStoreReason = _repository.GetCannotStoreReason(financialEntry);

            if (cannotStoreReason != null)
            {
                return(UnprocessableEntity(cannotStoreReason.GetCause()));
            }

            var model = _repository.Insert(financialEntry);

            return(Created($"/stores/{model.Id}", model));
        }
예제 #4
0
        //[SessionExpire]
        public async Task <ActionResult> GetProfile(string customerNo)
        {
            string profileServiceURL = ConfigurationManager.AppSettings["ProfileService.Url"];

            List <FinancialEntry> list = new List <FinancialEntry>();

            Models.ServiceFabric.FinancialProfile financialProfile = new Models.ServiceFabric.FinancialProfile();

            using (var client = new HttpClient())
            {
                string url = string.Format("services/profile/{0}", customerNo);
                client.BaseAddress = new Uri(profileServiceURL);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                //client.DefaultRequestHeaders.Add("token", this.SessionToken);

                HttpResponseMessage response = await client.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    financialProfile = await response.Content.ReadAsAsync <Models.ServiceFabric.FinancialProfile>();

                    if (financialProfile != null)
                    {
                        #region ****** Manually build list ******
                        FinancialEntry entry = new FinancialEntry();
                        entry.Name  = "TotalCashLimit";
                        entry.Type  = 1;
                        entry.Value = financialProfile.TotalCashLimit;
                        list.Add(entry);

                        entry       = new FinancialEntry();
                        entry.Name  = "TotalNonCashLimit";
                        entry.Type  = 1;
                        entry.Value = financialProfile.TotalNonCashLimit;
                        list.Add(entry);

                        entry       = new FinancialEntry();
                        entry.Name  = "TotalEarnedAssets";
                        entry.Type  = 1;
                        entry.Value = financialProfile.TotalEarnedAssets;
                        list.Add(entry);

                        entry       = new FinancialEntry();
                        entry.Name  = "TotalFreeFunds";
                        entry.Type  = 1;
                        entry.Value = financialProfile.TotalFreeFunds;
                        list.Add(entry);

                        entry       = new FinancialEntry();
                        entry.Name  = "TotalNBKFunds";
                        entry.Type  = 1;
                        entry.Value = financialProfile.TotalNBKFunds;
                        list.Add(entry);


                        entry       = new FinancialEntry();
                        entry.Name  = "TotalCashLiability";
                        entry.Type  = 2;
                        entry.Value = financialProfile.TotalCashLiability;
                        list.Add(entry);

                        entry       = new FinancialEntry();
                        entry.Name  = "TotalIndirectLiability";
                        entry.Type  = 2;
                        entry.Value = financialProfile.TotalIndirectLiability;
                        list.Add(entry);

                        entry       = new FinancialEntry();
                        entry.Name  = "TotalNonCashLiability";
                        entry.Type  = 2;
                        entry.Value = financialProfile.TotalNonCashLiability;
                        list.Add(entry);

                        entry       = new FinancialEntry();
                        entry.Name  = "TotalCollateral";
                        entry.Type  = 2;
                        entry.Value = financialProfile.TotalCollateral;
                        list.Add(entry);
                        #endregion

                        return(Content(JsonConvert.SerializeObject(list)));
                    }
                    else
                    {
                        HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                        return(Content("Customer not found"));
                    }
                }
                else
                {
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    return(Content(response.ReasonPhrase));
                }
            }
        }