public IHttpActionResult GetAlarmMessageByFactoryId(int factoryId, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc") { try { FactoryModels factoryModel = new FactoryModels(); int companyId = factoryModel.getFactoryById(factoryId).CompanyId; 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.GetAlarmMessageByFactoryId(factoryId, 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)); } }
public IHttpActionResult GetAlarmMessageByEquipmentId(int factoryId, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc") { try { int companyId = GetCompanyIdFromToken(); if (!General.IsFactoryUnderCompany(factoryId, companyId)) { return(Unauthorized()); } CompanyModels companyModel = new CompanyModels(); CompanyModels.Detail company = companyModel.getCompanyById(companyId); DocumentDBHelper docDBHelpler = new DocumentDBHelper(companyId, company.DocDBConnectionString); return(Ok(docDBHelpler.GetAlarmMessageByFactoryId(factoryId, 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()); } }