Ejemplo n.º 1
0
        private List <LoanDetailModel> GetData(int serviceId, int securityId, bool writeDataFlag)
        {
            try
            {
                using (HttpClient client = HTTPClientFactory.GetClient())
                {
                    var apiResponse = client.GetAsync(ConfigurationManager.AppSettings["APIBaseURL"] + "/api/" + serviceId + "/" + securityId + "/" + writeDataFlag).Result;

                    if (apiResponse.IsSuccessStatusCode)
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(List <LoanDetailModel>));
                        using (Stream stream = apiResponse.Content.ReadAsStreamAsync().Result)
                        {
                            return((List <LoanDetailModel>)serializer.Deserialize(stream));
                        }
                    }
                    else
                    {
                        throw new Exception(apiResponse.ReasonPhrase);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieve tasks for particular executive.
        /// </summary>
        /// <param name="assignee"></param>
        /// <returns></returns>
        public async Task <IEnumerable <TaskModel> > GetByAssignee(string assignee)
        {
            try
            {
                using (HttpClient client = HTTPClientFactory.GetClient())
                {
                    var apiResponse = await client.GetAsync("api/Task?assignee=" + assignee);

                    if (apiResponse.IsSuccessStatusCode)
                    {
                        return(apiResponse.Content.ReadAsAsync <IEnumerable <TaskModel> >().Result);
                    }
                    else if (apiResponse.StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        return(null);
                    }
                    else
                    {
                        throw new Exception(apiResponse.StatusCode.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieve a task by taskId.
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        public async Task <TaskModel> GetById(int taskId)
        {
            try
            {
                using (HttpClient client = HTTPClientFactory.GetClient())
                {
                    var apiResponse = await client.GetAsync("api/Task/" + taskId);

                    if (apiResponse.IsSuccessStatusCode)
                    {
                        return(apiResponse.Content.ReadAsAsync <TaskModel>().Result);
                    }
                    else if (apiResponse.StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        return(null);
                    }
                    else
                    {
                        throw new Exception(apiResponse.StatusCode.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Delete a task.
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        public async Task <bool> Delete(int taskId)
        {
            try
            {
                using (HttpClient client = HTTPClientFactory.GetClient())
                {
                    var apiResponse = await client.DeleteAsync("api/Task/" + taskId);

                    if (apiResponse.IsSuccessStatusCode)
                    {
                        return(true);
                    }
                    else
                    {
                        throw new Exception(apiResponse.StatusCode.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Update the status of a task specified by TaskId.
        /// </summary>
        /// <param name="taskToUpdate"></param>
        /// <returns></returns>
        public async Task <bool> UpdateStatus(TaskModel taskToUpdate)
        {
            try
            {
                using (HttpClient client = HTTPClientFactory.GetClient())
                {
                    var apiResponse = await client.PutAsJsonAsync("api/Task/UpdateStatus", taskToUpdate);

                    if (apiResponse.IsSuccessStatusCode)
                    {
                        return(true);
                    }
                    else
                    {
                        throw new Exception(apiResponse.StatusCode.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }