Exemplo n.º 1
0
        public IHttpActionResult GetAlarmMessageByEquipmentId(int equipmentId, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc")
        {
            try
            {
                EquipmentModels        equipmentModel = new EquipmentModels();
                EquipmentModels.Detail equipment      = equipmentModel.getEquipmentById(equipmentId);
                CompanyModel           companyModel   = new CompanyModel();
                var companySubscription       = companyModel.GetValidSubscriptionPlanByCompanyId(equipment.CompanyId);
                DocumentDBHelper docDBHelpler = new DocumentDBHelper(equipment.CompanyId, companySubscription.CosmosDBConnectionString);
                return(Ok(docDBHelpler.GetAlarmMessageByEquipmentId(equipment.EquipmentId, 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));
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult GetAlarmMessageByEquipmentId(int equipmentId, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc")
        {
            try
            {
                int companyId = Global.GetCompanyIdFromToken();
                if (!General.IsEquipmentUnderCompany(equipmentId, companyId))
                {
                    return(Unauthorized());
                }

                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);
                EquipmentModels  equipmentModel = new EquipmentModels();

                return(Ok(docDBHelpler.GetAlarmMessageByEquipmentId(equipmentModel.getEquipmentById(equipmentId).EquipmentId, top, hours, order, companyId)));
            }
            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.º 3
0
        public IHttpActionResult GetAlarmMessageByEquipmentId(string equipmentId, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc")
        {
            try
            {
                EquipmentModels      equipmentModel = new EquipmentModels();
                int                  companyId      = equipmentModel.getCompanyId(equipmentId);
                CompanyModels        companyModel   = new CompanyModels();
                CompanyModels.Detail company        = companyModel.getCompanyById(companyId);
                DocumentDBHelper     docDBHelpler   = new DocumentDBHelper(companyId, company.DocDBConnectionString);
                return(Ok(docDBHelpler.GetAlarmMessageByEquipmentId(equipmentId, 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
             * {
             *  EquipmentModels equipmentModel = new EquipmentModels();
             *  int companyId = equipmentModel.getCompanyId(equipmentId);
             *  DocDB_AlarmMessageModels alarmMessageModel = new DocDB_AlarmMessageModels(companyId);
             *  return Ok(alarmMessageModel.GetByEquipmentId(equipmentId, 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.º 4
0
        public IHttpActionResult GetAlarmMessageByEquipmentId(string equipmentId, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc")
        {
            try
            {
                int companyId = GetCompanyIdFromToken();
                if (!General.IsEquipmentUnderCompany(equipmentId, companyId))
                {
                    return(Unauthorized());
                }

                CompanyModels        companyModel = new CompanyModels();
                CompanyModels.Detail company      = companyModel.getCompanyById(companyId);
                DocumentDBHelper     docDBHelpler = new DocumentDBHelper(companyId, company.DocDBConnectionString);
                return(Ok(docDBHelpler.GetAlarmMessageByEquipmentId(equipmentId, top, hours, order, companyId)));
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                string        logAPI     = "[Get] " + Request.RequestUri.ToString();
                Startup._sfAppLogger.Error(logAPI + logMessage);

                return(InternalServerError(ex));
            }
        }