Пример #1
0
        public ActionResult GetConsultantApplications(string email, int year, int month, int service_id)
        {
            ConsultantChartParams parameters = new ConsultantChartParams
            {
                Year      = year,
                Month     = month,
                ServiceId = service_id,
                Email     = email
            };

            ServiceConsultantsData data = null;

            using (HttpClient client = WebApiClient.InitializeClient(Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/"))
            {
                HttpResponseMessage message = client.PostAsJsonAsync("/api/ServiceConsultants/ConsultantStats", parameters).Result;

                if (message.IsSuccessStatusCode)
                {
                    data = message.Content.ReadAsAsync <ServiceConsultantsData>().Result;
                }
            }

            if (data != null)
            {
                return(PartialView("_ConsultantStats", data));
            }

            return(null);
        }
        public HttpResponseMessage ConsultantCharts([FromBody] ConsultantChartParams parameters)
        {
            using (SqlConnection connection = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
            {
                SqlDataAdapter da = new SqlDataAdapter("spGetConsultantApplicationsData", connection);

                da.SelectCommand.CommandType = CommandType.StoredProcedure;

                da.SelectCommand.Parameters.AddWithValue("@ServiceId", parameters.ServiceId);
                da.SelectCommand.Parameters.AddWithValue("@TimeLimit", new DateTime(parameters.Year, parameters.Month, 1));
                da.SelectCommand.Parameters.AddWithValue("@ConsultantEmail", parameters.Email);

                DataSet set = new DataSet();

                try
                {
                    ServiceConsultantsData data = new ServiceConsultantsData();

                    da.Fill(set);

                    if (set.Tables[0].Rows.Count > 0)
                    {
                        data.AdvancePendingApplications = Convert.ToInt32(set.Tables[0].Rows[0]["AdvancePendingCount"].ToString());
                        data.MainPendingApplications    = Convert.ToInt32(set.Tables[0].Rows[0]["MainPendingCount"].ToString());
                        data.NoBillApplications         = Convert.ToInt32(set.Tables[0].Rows[0]["NoBillCount"].ToString());
                        data.MainPaidApplications       = Convert.ToInt32(set.Tables[0].Rows[0]["MainPaidCount"].ToString());
                        if (set.Tables[0].Rows[0]["AverageMark"].ToString() != "")
                        {
                            data.AverageMark = Convert.ToDouble(set.Tables[0].Rows[0]["AverageMark"].ToString());
                        }
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, data));
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
                }
            }
        }