public ActionResult SaveUploadedFiles(int BuildingId, int filenumber, int noOfFiles) { var UploadedFile = new CreateUploadFilesInput(); try { if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any()) { var file = System.Web.HttpContext.Current.Request.Files["HelpSectionImages" + filenumber]; HttpPostedFileBase filebase = new HttpPostedFileWrapper(file); //var fileName = Path.GetFileName(filebase.FileName); //var path = Path.Combine(Server.MapPath("~/UploadedFiles/"), fileName); //filebase.SaveAs(path); using (var binaryReader = new BinaryReader(file.InputStream)) { UploadedFile.FileData = binaryReader.ReadBytes(file.ContentLength); } UploadedFile.buildingId = BuildingId; UploadedFile.Type = file.ContentType; UploadedFile.FileName = file.FileName; UploadedFile.NoOfFiles = noOfFiles; _uploadFilesAppService.Create(UploadedFile); return(Json("File Saved Successfully.")); } else { return(Json("No File Saved.")); } } catch (Exception ex) { return(Json("Error While Saving.")); } }
//[AllowAnonymous] // [Route("Building/EditBuildingModal")] // [ValidateAntiForgeryToken] // [AjaxValidateAntiForgeryToken] // [ValidateAntiForgeryTokenOnAllPosts] public ActionResult UploadFiles(HttpPostedFileBase[] files, int BuildingId)// not used 08082018 { var UploadedFile = new CreateUploadFilesInput(); //Ensure model state is valid if (ModelState.IsValid) { //iterating through multiple file collection foreach (/*HttpPostedFileBase*/ var file in files) { //Checking file is available to save. if (file != null) { //-----*** commited for not saving files to server ***----- //var InputFileName = Path.GetFileName(file.FileName); //var ServerSavePath = Path.Combine(Server.MapPath("~/UploadedFiles/") + InputFileName); ////Save file to server folder //file.SaveAs(ServerSavePath); ////assigning file uploaded status to ViewBag for showing message to user. /// /// /// ViewBag.UploadStatus = files.Count().ToString() + " files uploaded successfully."; // // // convert file data (inputStream) to array byte[] in order // to store it in database using (var binaryReader = new BinaryReader(file.InputStream)) { UploadedFile.FileData = binaryReader.ReadBytes(file.ContentLength); } //dont forget to add insertAndGetIdAsync to check if the row is inserted, // if yes return success message // add the other properties of the createUploadFilesInput object like sourcetable.. _uploadFilesAppService.Create(UploadedFile); } } } //populate the view add data to the model ////get the list of buildingTypes var buildingTypes = _buildingTypeAppService.getAllBuildingtype().ToList(); //// get the list of neighborhoods var neighborhoods = _neighborhoodAppService.GetAllNeighborhood().ToList(); var getBuidlingsInput = new GetBuidlingsInput { Id = BuildingId }; var getBuildingOutput = _buildingsAppService.getBuildingsById(getBuidlingsInput); var BuildingViewModel = new BuildingViewModel { Building = getBuildingOutput, BuildingTypes = buildingTypes, Neighborhoods = neighborhoods }; //=================================== // return PartialView("_EditUserModal", BuildingViewModel); // return null; // return RedirectToAction("EditBuildingModal",new { userId = BuildingId }); // return Json(new { Result = true }, JsonRequestBehavior.AllowGet); return(null); }
public async Task Create(CreateUploadFilesInput input) { var outPut = Mapper.Map <CreateUploadFilesInput, Models.UploadFiles>(input); await _uploadFilesManager.Create(outPut); }