Exemplo n.º 1
0
        public IHttpActionResult GetAlarmMessageByCompanyId([FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc")
        {
            try
            {
                int          companyId             = Global.GetCompanyIdFromToken();
                CompanyModel companyModel          = new CompanyModel();
                CompanyModel.Format_Detail company = companyModel.GetById(companyId);

                var companySubscription = companyModel.GetValidSubscriptionPlanByCompanyId(companyId);
                if (companySubscription == null)
                {
                    throw new Exception("can't find valid subscription plan.");
                }

                DocumentDBHelper docDBHelpler = new DocumentDBHelper(companyId, companySubscription.CosmosDBConnectionString);
                return(Ok(docDBHelpler.GetAlarmMessageByCompanyId(companyId, top, hours, order)));
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogHelper.BuildExceptionMessage(ex);
                string        logAPI     = "[Get] " + Request.RequestUri.ToString();
                Global._appLogger.Error(logAPI + logMessage);

                return(Content(HttpStatusCode.InternalServerError, ex));
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult GetAlarmMessageByCompanyId(int companyId, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc")
        {
            try
            {
                CompanyModels        companyModel = new CompanyModels();
                CompanyModels.Detail company      = companyModel.getCompanyById(companyId);
                DocumentDBHelper     docDBHelpler = new DocumentDBHelper(companyId, company.DocDBConnectionString);
                return(Ok(docDBHelpler.GetAlarmMessageByCompanyId(companyId, top, hours, order)));
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                string        logAPI     = "[Get] " + Request.RequestUri.ToString();
                Startup._sfAppLogger.Error(logAPI + logMessage);

                return(InternalServerError(ex));
            }
            //try
            //{
            //    DocDB_AlarmMessageModels alarmMessageModel = new DocDB_AlarmMessageModels(companyId);
            //    return Ok(alarmMessageModel.GetByCompanyId(companyId, top, hours, order));
            //}
            //catch (Exception ex)
            //{
            //    StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
            //    string logAPI = "[Get] " + Request.RequestUri.ToString();
            //    Startup._sfAppLogger.Error(logAPI + logMessage);

            //    return InternalServerError(ex);
            //}
        }
Exemplo n.º 3
0
        public IHttpActionResult GetAlarmMessageByCompanyId(int companyId, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc")
        {
            try
            {
                CompanyModel companyModel          = new CompanyModel();
                CompanyModel.Format_Detail company = companyModel.GetById(companyId);
                var companySubscription            = companyModel.GetValidSubscriptionPlanByCompanyId(companyId);
                DocumentDBHelper docDBHelpler      = new DocumentDBHelper(companyId, companySubscription.CosmosDBConnectionString);
                return(Ok(docDBHelpler.GetAlarmMessageByCompanyId(companyId, top, hours, order)));
            }
            catch (CDSException cdsEx)
            {
                IHttpActionResult   response;
                HttpResponseMessage responseMsg = new HttpResponseMessage(HttpStatusCode.BadRequest);
                string body = new JavaScriptSerializer().Serialize(CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId));
                responseMsg.Content = new StringContent(body, Encoding.UTF8, "application/json");
                response            = ResponseMessage(responseMsg);
                return(response);
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogHelper.BuildExceptionMessage(ex);
                string        logAPI     = "[Get] " + Request.RequestUri.ToString();
                Global._appLogger.Error(logAPI + logMessage);

                return(Content(HttpStatusCode.InternalServerError, ex));
            }
        }