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)); } }
public IHttpActionResult GetMessageByEquipmentId(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.GetMessageByEquipmentId(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)); } }