public ActionResult BMBuildingUploadInfo() { //guard clause if (Request.Files == null || Request.Files.Count == 0) { return(Json(false, JsonRequestBehavior.AllowGet)); } //check if request has valid keys var requestResult = BuildingRequestHelper.GetRequestResult(Request); if (!requestResult.IsValid) { return(Json(false, JsonRequestBehavior.AllowGet)); } //identify type of file uploaded ( excel or csv) bool success = false; var message = "There was a problem with the upload. Please contact administrator."; List <ApartmentViewModel> list = null; if (Request.Files[0] != null && Request.Files[0].ContentLength > 0) { var uploadedFile = Request.Files[0]; var extension = Path.GetExtension(uploadedFile.FileName); try { //TODO: the static factory causes some issue with repo dependencies //var dataSourceManager = DataSourceServiceFactory.GetService(extension); var building = _buildingRepo.GetById(requestResult.BuildingId); if (building == null) { throw new ArgumentNullException("building"); } var apartmentData = ApartmentManager.MapDataSourceToApartment(uploadedFile, requestResult.BuildingId) as List <Apartment>; if (apartmentData != null && apartmentData.Count > 0) { list = apartmentData.Select(apt => { var vm = ApartmentViewModel.CreateModel(apt); return(vm); }).ToList(); success = true; message = string.Concat("Successully uploaded ", uploadedFile.FileName); } } catch (Exception ex) { LogHelper.Error <BMBuildingController>(ex.Message, ex); success = false; } } return(Json(new { success, message, list }, JsonRequestBehavior.AllowGet)); }
public ActionResult BMBuildingApartmentUploadInfo() { //check if request has valid keys bool success = false; var requestResult = BuildingRequestHelper.GetAptRequestResult(Request); if (!requestResult.IsValid) { return(Json(false, JsonRequestBehavior.AllowGet)); } //check if apartment does exist List <string> apartmentIdentifiers = new List <string>(); IList <ApartmentAssetViewModel> list = null; var apartment = _apartmentRepo.GetById(requestResult.ApartmentId); if (apartment != null) { apartmentIdentifiers.Add(apartment.Name); var account = _accountRepo.GetById(requestResult.AccountId); var building = _buildingRepo.GetById(requestResult.BuildingId); if (account != null && building != null) { var result = MediaManager.CreateFolder(account.Name, account.Id, building.Name, building.Id, apartmentIdentifiers); if (result.MediaApartmentFolderIds != null && result.MediaApartmentFolderIds.Count > 0) { var aptMediaFolderId = result.MediaApartmentFolderIds.FirstOrDefault(); var mediaList = MediaManager.UploadMediaFiles(Request.Files, building.Id, aptMediaFolderId, apartment.Id); if (mediaList != null && mediaList.Count > 0) { //identify the file assets for the apartment var assets = MediaManager.GetApartmentMediaAssets(apartment.Id); if (assets != null && assets.Count > 0) { list = assets.Select(x => { return(new ApartmentAssetViewModel { MediaId = x.Id, Url = Umbraco.TypedMedia(x.Id).Url }); }).ToList(); success = true; } } } } } return(Json(new { success, list }, JsonRequestBehavior.AllowGet)); }
public ActionResult BMBuildingUploadAssets() { //guard clause if (Request.Files == null || Request.Files.Count == 0) { return(Json(false, JsonRequestBehavior.AllowGet)); } //check if request has valid keys var requestResult = BuildingRequestHelper.GetRequestResult(Request); if (!requestResult.IsValid) { return(Json(false, JsonRequestBehavior.AllowGet)); } IList <MediaViewModel> uploadedMediaList = null; var account = _accountRepo.GetById(requestResult.AccountId); var building = _buildingRepo.GetById(requestResult.BuildingId); if (account != null && building != null) { var result = MediaManager.CreateFolder(account.Name, account.Id, building.Name, building.Id); if (result.MediaBuildingFolderId > 0) { var mediaList = MediaManager.UploadMediaFiles(Request.Files, building.Id, result.MediaBuildingFolderId); if (mediaList != null && mediaList.Count > 0) { uploadedMediaList = mediaList.Select(x => { var url = Umbraco.TypedMedia(x.Id) != null ? Umbraco.TypedMedia(x.Id).Url : ""; return(MediaViewModel.CreateModel(x, url)); }).ToList(); } } } return(new JsonResult { Data = new { hasData = uploadedMediaList.Count > 0, list = uploadedMediaList }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public JsonResult BMBuildingInfo() { //check if request has valid keys var requestResult = BuildingRequestHelper.GetRequestResult(Request); if (!requestResult.IsValid) { return(Json(false, JsonRequestBehavior.AllowGet)); } bool success = false; //get the apartments registered on db for the building var apartments = ApartmentManager.GetApartments(requestResult.BuildingId); List <ApartmentViewModel> list = null; if (apartments != null && apartments.Count > 0) { list = apartments.Select(apt => { var vm = ApartmentViewModel.CreateModel(apt); //identify the file assets for the apartment //var apartment = _apartmentRepo.GetById(apt.Id); var assets = MediaManager.GetApartmentMediaAssets(apt.Id); if (assets != null && assets.Count > 0) { vm.FileAssets = assets.Select(x => { return(new ApartmentAssetViewModel { MediaId = x.Id, Url = Umbraco.TypedMedia(x.Id).Url }); }).ToList <ApartmentAssetViewModel>(); } return(vm); }).ToList(); success = true; } return(Json(new { success, list }, JsonRequestBehavior.AllowGet)); }
public ActionResult BMBuildingSortAssets() { //guard clause var requestResult = BuildingRequestHelper.GetRequestResult(Request); if (!requestResult.IsValid) { return(Json(false, JsonRequestBehavior.AllowGet)); } //guard close if (Request.Form[MEDIAUPDATE_KEY] == null) { return(Json(false, JsonRequestBehavior.AllowGet)); } //update the sorting order var mediaList = Request.Form[MEDIAUPDATE_KEY].ToString().Split(new char[] { ',' }); foreach (var mediaItem in mediaList) { var mediaInfoItem = mediaItem.Split(new char[] { '|' }); var mediaId = mediaInfoItem[0]; var mediaSortOrder = mediaInfoItem[1]; var mediaName = mediaInfoItem[2]; var media = MediaManager.GetMediaAsset(int.Parse(mediaId)); if (media != null) { //update the sort order property media.SortOrder = int.Parse(mediaSortOrder); media.Name = mediaName; MediaManager.UpdateMediaAsset(media); } } return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult BMBuildingAssets() { var requestResult = BuildingRequestHelper.GetRequestResult(Request); if (!requestResult.IsValid) { return(Json(false, JsonRequestBehavior.AllowGet)); } //find building from custom table; var building = _buildingRepo.GetById(requestResult.BuildingId); IList <MediaViewModel> uploadedMediaList = null; if (building != null && building.AccountId == requestResult.AccountId) { var list = MediaManager.GetBuildingMediaAssets(building.Id); list = list.OrderBy(i => i.SortOrder).ToList(); if (list != null && list.Count > 0) { uploadedMediaList = list.Select(x => { var url = Umbraco.TypedMedia(x.Id) != null ? Umbraco.TypedMedia(x.Id).Url : ""; return(MediaViewModel.CreateModel(x, url)); }).ToList(); } } return(new JsonResult { Data = new { list = uploadedMediaList }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }