Exemple #1
0
        public IHttpActionResult GetMessageByEquipmentId(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.GetMessageByEquipmentId(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));
            }
        }
Exemple #2
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));
            }
        }
Exemple #3
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));
            }

            EquipmentModels equipmentModel = new EquipmentModels();
            FileUtility     fileHelper     = new FileUtility();
            string          root           = Path.GetTempPath();
            var             provider       = new MultipartFormDataStreamProvider(root);

            try
            {
                EquipmentModels.Detail equipment = equipmentModel.getEquipmentById(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-" + equipmentModel.getCompanyId(id) + "/equipment/" + 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
                equipmentModel.updateEquipmentLogoURL(id, fileAbsoluteUri);
                return(Request.CreateResponse(HttpStatusCode.OK, new { imageURL = fileAbsoluteUri }));
            }
            catch (System.Exception ex)
            {
                string        logAPI     = "[Put] " + Request.RequestUri.ToString();
                StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                Startup._sfAppLogger.Error(logAPI + logMessage);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Exemple #4
0
        public IHttpActionResult GeById(int id)
        {
            EquipmentModels equipmentModel = new EquipmentModels();

            try
            {
                EquipmentModels.Detail company = equipmentModel.getEquipmentById(id);
                return(Ok(company));
            }
            catch
            {
                return(NotFound());
            }
        }