Пример #1
0
        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;
                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)));
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                string        logAPI     = "[Get] " + Request.RequestUri.ToString();
                Startup._sfAppLogger.Error(logAPI + logMessage);

                return(InternalServerError(ex));
            }
            //try
            //{
            //    FactoryModels factoryModel = new FactoryModels();
            //    int companyId = factoryModel.getFactoryById(factoryId).CompanyId;
            //    DocDB_AlarmMessageModels alarmMessageModel = new DocDB_AlarmMessageModels(companyId);
            //    return Ok(alarmMessageModel.GetByFactoryId(factoryId, 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);
            //}
        }
Пример #2
0
        public async Task <HttpResponseMessage> UploadLogoFile(int id)
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                return(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));
            }

            CompanyModels companyModel = new CompanyModels();
            FileUtility   fileHelper   = new FileUtility();
            string        root         = Path.GetTempPath();
            var           provider     = new MultipartFormDataStreamProvider(root);

            try
            {
                CompanyModels.Detail company = companyModel.getCompanyById(id);
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            try
            {
                // Read the form data.
                string fileAbsoluteUri = "";
                await Request.Content.ReadAsMultipartAsync(provider);

                //FileData
                foreach (MultipartFileData fileData in provider.FileData)
                {
                    string formColumnName   = fileData.Headers.ContentDisposition.Name;
                    string fileExtenionName = fileData.Headers.ContentDisposition.FileName.Split('.')[1];
                    if (fileHelper.CheckImageExtensionName(formColumnName, fileExtenionName))
                    {
                        string uploadFilePath = "company-" + id + "/" + id + "-default." + fileHelper.LowerAndFilterString(fileExtenionName);
                        fileAbsoluteUri = fileHelper.SaveFiletoStorage(fileData.LocalFileName, uploadFilePath, "images");
                    }
                }

                if (fileAbsoluteUri.Equals(""))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "File is empty or wrong extension name"));
                }

                //Edit company logo path
                companyModel.updateCompanyLogoURL(id, fileAbsoluteUri);
                RedisCacheHelper.DeleteCompanyCache(id);
                return(Request.CreateResponse(HttpStatusCode.OK, new { imageURL = fileAbsoluteUri }));
            }
            catch (System.Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
Пример #3
0
        public IHttpActionResult GetMessageByCompanyId(int id, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc")
        {
            try
            {
                CompanyModels        companyModel = new CompanyModels();
                CompanyModels.Detail company      = companyModel.getCompanyById(id);
                DocumentDBHelper     docDBHelpler = new DocumentDBHelper(id, company.DocDBConnectionString);
                return(Ok(docDBHelpler.GetMessageByCompanyId(id, 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));
            }
        }
Пример #4
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);
             * }*/
        }
Пример #5
0
        public IHttpActionResult GetCompanyById(int id)
        {
            RedisKey cacheKey   = "company_" + id;
            string   cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);

            if (cacheValue == null)
            {
                CompanyModels companyModel = new CompanyModels();
                try
                {
                    CompanyModels.Detail company = companyModel.getCompanyById(id);
                    RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(company));
                    return(Ok(company));
                }
                catch
                {
                    return(NotFound());
                }
            }
            else
            {
                return(Ok(new JavaScriptSerializer().Deserialize <Object>(cacheValue)));
            }
        }
Пример #6
0
        public IHttpActionResult GetMessageByEquipmentId(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.GetMessageByEquipmentId(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));
            }
        }