public IActionResult GetSnapshotIndicators([FromBody] SnapshotRequestModel snapshotRequestModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            SnapshotResponseModel snapshotResponseModel;

            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);

                snapshotResponseModel = _imisModules.GetReportModule().GetReportLogic().GetSnapshotIndicators(snapshotRequestModel, officerCode);
            }
            catch (ValidationException e)
            {
                return(BadRequest(new { error = new { message = e.Message, value = e.Value } }));
            }

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

            return(Ok(snapshotResponseModel));
        }
        public SnapshotResponseModel GetSnapshotIndicators(SnapshotRequestModel snapshotRequestModel, string officerCode)
        {
            SnapshotResponseModel response;

            response = reportRepository.GetSnapshotIndicators(snapshotRequestModel, officerCode);

            return(response);
        }
        public SnapshotResponseModel GetSnapshotIndicators(SnapshotRequestModel snapshotRequestModel, string officerCode)
        {
            SnapshotResponseModel response = new SnapshotResponseModel();

            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 snapshotDateParameter = new SqlParameter("@SnapshotDate", snapshotRequestModel.SnapshotDate)
                {
                    SqlDbType = SqlDbType.Date
                };
                var officerIdParameter = new SqlParameter("@OfficerId", officerId);

                var sql = "SELECT Active, Expired, Idle, Suspended FROM udfGetSnapshotIndicators(@SnapshotDate,@OfficerId)";

                DbConnection connection = imisContext.Database.GetDbConnection();

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

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

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

                    using (var reader = cmd.ExecuteReader())
                    {
                        do
                        {
                            while (reader.Read())
                            {
                                response.Active    = int.Parse(reader["Active"].ToString());
                                response.Expired   = int.Parse(reader["Expired"].ToString());
                                response.Idle      = int.Parse(reader["Idle"].ToString());
                                response.Suspended = int.Parse(reader["Suspended"].ToString());
                            }
                        } while (reader.NextResult());
                    }
                }
            }

            return(response);
        }