Пример #1
0
        public IActionResult GetCumulativeIndicators([FromBody] IndicatorRequestModel cumulativeRequestModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            CumulativeIndicatorsResponseModel cumulativeIndicatorsResponseModel;

            try
            {
                Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault());

                Repository rep         = new Repository();
                string     officerCode = rep.GetLoginNameByUserUUID(userUUID);

                cumulativeIndicatorsResponseModel = _imisModules.GetReportModule().GetReportLogic().GetCumulativeIndicators(cumulativeRequestModel, officerCode);
            }
            catch (ValidationException e)
            {
                return(BadRequest(new { error = new { message = e.Message, value = e.Value } }));
            }

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

            return(Ok(cumulativeIndicatorsResponseModel));
        }
Пример #2
0
        public CumulativeIndicatorsResponseModel GetCumulativeIndicators(IndicatorRequestModel cumulativeIndicatorsRequestModel, string officerCode)
        {
            CumulativeIndicatorsResponseModel response;

            response = reportRepository.GetCumulativeIndicators(cumulativeIndicatorsRequestModel, officerCode);

            return(response);
        }
Пример #3
0
        public CumulativeIndicatorsResponseModel GetCumulativeIndicators(IndicatorRequestModel cumulativeIndicatorsRequestModel, string officerCode)
        {
            CumulativeIndicatorsResponseModel response = new CumulativeIndicatorsResponseModel();

            int officerId;

            using (var imisContext = new ImisDB())
            {
                officerId = (from O in imisContext.TblOfficer
                             where O.Code == officerCode &&
                             O.ValidityTo == null
                             select O.OfficerId)
                            .FirstOrDefault();

                var dateFromParameter = new SqlParameter("@DateFrom", cumulativeIndicatorsRequestModel.FromDate)
                {
                    SqlDbType = SqlDbType.Date
                };
                var dateToParameter = new SqlParameter("@DateTo", cumulativeIndicatorsRequestModel.ToDate)
                {
                    SqlDbType = SqlDbType.Date
                };
                var officerIdParameter = new SqlParameter("@OfficerId", officerId);

                var sql = "SELECT " +
                          " ISNULL(dbo.udfNewPoliciesPhoneStatistics(@DateFrom,@DateTo,@OfficerId),0) NewPolicies," +
                          " ISNULL(dbo.udfRenewedPoliciesPhoneStatistics(@DateFrom,@DateTo,@OfficerId),0) RenewedPolicies, " +
                          " ISNULL(dbo.udfExpiredPoliciesPhoneStatistics(@DateFrom,@DateTo,@OfficerId),0) ExpiredPolicies,  " +
                          " ISNULL(dbo.udfSuspendedPoliciesPhoneStatistics(@DateFrom,@DateTo,@OfficerId),0) SuspendedPolicies," +
                          " ISNULL(dbo.udfCollectedContribution(@DateFrom,@DateTo,@OfficerId),0) CollectedContribution ";

                DbConnection connection = imisContext.Database.GetDbConnection();

                using (DbCommand cmd = connection.CreateCommand())
                {
                    cmd.CommandText = sql;

                    cmd.Parameters.AddRange(new[] { dateFromParameter, dateToParameter, officerIdParameter });

                    if (connection.State.Equals(ConnectionState.Closed))
                    {
                        connection.Open();
                    }

                    using (var reader = cmd.ExecuteReader())
                    {
                        do
                        {
                            while (reader.Read())
                            {
                                response.NewPolicies           = int.Parse(reader["NewPolicies"].ToString());
                                response.RenewedPolicies       = int.Parse(reader["RenewedPolicies"].ToString());
                                response.ExpiredPolicies       = int.Parse(reader["ExpiredPolicies"].ToString());
                                response.SuspendedPolicies     = int.Parse(reader["SuspendedPolicies"].ToString());
                                response.CollectedContribution = Math.Round(double.Parse(reader["CollectedContribution"].ToString()), 2);
                            }
                        } while (reader.NextResult());
                    }
                }
            }

            return(response);
        }