public JObject Upload() { try { if (_fileUploader.GetFiles().Count == 0) { Logger.Error("No File Found for upload"); return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } string uploadCollection = _paramContainer.GetKey(CommonConst.CommonValue.COLLECTION); if (string.IsNullOrEmpty(uploadCollection)) { uploadCollection = CommonConst.Collection.STATIC_CONTECT; } string storegeType = _paramContainer.GetKey("storege_type"); string baseFolder = _paramContainer.GetKey(CommonConst.CommonValue.BASE_PATH); if (storegeType.Trim().ToLower() == "file") { var fileName = _fileUploader.GetFiles()[0]; string filePath = string.Format("{0}\\{1}", baseFolder, fileName); var reponse = _fileUploader.Save(fileName, filePath); if (!string.IsNullOrEmpty(reponse)) { return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS)); } else { Logger.Error("_fileUploader.Save fail"); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } } else { if (string.IsNullOrEmpty(baseFolder)) { baseFolder = "/"; } JObject fileResonse = _fileUploader.SaveToDB(DBProxy, _fileUploader.GetFiles()[0], baseFolder, uploadCollection); if (fileResonse[CommonConst.CommonField.DATA] != null) { fileResonse.Remove(CommonConst.CommonField.DATA); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, fileResonse)); } else { Logger.Error("_fileUploader.SaveToDB fail"); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR, fileResonse)); } } } catch (Exception ex) { Logger.Error(string.Format("Error in FileUploadController.Upload : {0} ", ex.Message), ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public JObject AdminChangeUserImage() { var user_id = HttpProxy.GetQueryString(CommonConst.CommonField.USER_ID); if (string.IsNullOrEmpty(user_id)) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } Logger.Debug(string.Format("File Count {0}", _fileUploader.GetFiles().Count)); if (_fileUploader.GetFiles().Count > 0) { var path = string.Format("/frontend/{0}/{1}", "userpic", user_id); FileInfo fi = new FileInfo(_fileUploader.GetFiles()[0]); Logger.Debug(string.Format("Getting File Data")); byte[] fileData = _fileUploader.GetFileData(_fileUploader.GetFiles()[0]); JObject uploadReponse = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, Convert.ToBase64String(fileData)); Logger.Debug(string.Format("Uploaded default file"), uploadReponse); JObject uploadReponseS = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, ImageUtility.GetSmallImage(fileData)); Logger.Debug(string.Format("Uploaded small file"), uploadReponseS); JObject uploadReponseM = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, ImageUtility.GetMediumImage(fileData)); Logger.Debug(string.Format("Uploaded medium file"), uploadReponseM); JObject uploadReponseL = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, ImageUtility.GetLargeImage(fileData)); Logger.Debug(string.Format("Uploaded large file"), uploadReponseL); if (uploadReponse != null && uploadReponseS != null && uploadReponseM != null && uploadReponseL != null) { var filePath = uploadReponse[CommonConst.CommonField.FILE_PATH].ToString(); var filePathS = uploadReponseS[CommonConst.CommonField.FILE_PATH].ToString(); var filePathM = uploadReponseM[CommonConst.CommonField.FILE_PATH].ToString(); var filePathL = uploadReponseL[CommonConst.CommonField.FILE_PATH].ToString(); JObject updateFilter = new JObject(); updateFilter[CommonConst.CommonField.USER_ID] = user_id; JObject userdata = new JObject(); userdata[ModuleAppConsts.Field.USER_PIC] = filePath; userdata[ModuleAppConsts.Field.USER_PIC_S] = filePathS; userdata[ModuleAppConsts.Field.USER_PIC_M] = filePathM; userdata[ModuleAppConsts.Field.USER_PIC_L] = filePathL; userdata[CommonConst.CommonField.USER_ID] = user_id; Logger.Debug("Updating User AdminChangeUserImage", userdata); var updateCount = DBProxy.Update(CommonConst.Collection.USER_INFO, updateFilter.ToString(), userdata, true); Logger.Debug(string.Format("AdminChangeUserImage UpdateCount:{0}", userdata)); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, userdata)); } else { Logger.Error(string.Format("Error while uploading image AdminChangeUserImage")); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR, uploadReponse)); } } else { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } }