public FileResult DownloadCompanyDocument(int CompanyProfileId, int DocumentId) { var data = _companyProfileService.GetCompanyProfileById(CompanyProfileId); var document = data.CompanyDocuments.Where(a => a.Id == DocumentId).FirstOrDefault(); string filePath = _hostingEnvironment.WebRootPath + "\\CompanyDocuments\\" + document.DocumentPath; string fileName = document.DocumentPath; //filePath = $"{this.Request.Host}"; byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); //13/09/19 aakansha var model = new DownloadHistory(); model.DownloadDateTime = DateTime.UtcNow; model.DocumentName = Path.GetFileName(filePath); model.DocumentPath = filePath; model.DocumentFormat = Path.GetExtension(filePath); model.DocumentType = "CompanyDocuments"; model.ProcessTypeId = (int)ProcessType.Upload; model.UserId = _workContext.CurrentCustomer.Id; _companyProfileService.InsertDownloadHistory(model); return(File(fileBytes, "application/force-download", fileName)); }
public IActionResult UploadCompanyDocument() { var formData = this.Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString()); String[] documentName = formData["DocumentName"].Split(","); String[] CompanyProfileIds = formData["CompanyProfileId"].Split(","); var data = _companyProfileService.GetCompanyProfileById(Convert.ToInt32(CompanyProfileIds[0])); // Checking no of files injected in Request object if (Request.Form.Files.Count > 0) { var documentFile = Request.Form.Files[0]; try { if (documentFile != null) { string saveFilePath = _hostingEnvironment.WebRootPath + "\\CompanyDocuments"; var filePath = Path.Combine(saveFilePath, documentFile.FileName); using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write)) { documentFile.CopyToAsync(fileStream); } data.CompanyDocuments.Add(new CompanyDocument() { DocumentName = documentName[0].ToString(), DocumentPath = documentFile.FileName }); _companyProfileService.UpdateCompanyProfile(data); //16/09/19 aakansha var model = new DownloadHistory(); model.DownloadDateTime = DateTime.UtcNow; model.DocumentName = Path.GetFileName(filePath); model.DocumentPath = filePath; model.DocumentFormat = Path.GetExtension(filePath); model.DocumentType = "CompanyDocuments"; model.ProcessTypeId = (int)ProcessType.Upload; model.UserId = _workContext.CurrentCustomer.Id; _companyProfileService.InsertDownloadHistory(model); return(Json(data.Id)); } } catch (Exception ex) { AddNotification(NotificationMessage.TitleError, NotificationMessage.ErrorMsg, NotificationMessage.TypeError); return(Json(data.Id)); } } else { return(Json(data.Id)); } return(Json(data.Id)); }