// Add export attachmnents public void AddAttachments(CreateExportAttachment input) { try { var attachments = new ExportAttachment { ExportDetailId = input.ExportDetailId, BrelaRegistrationCert = input.BrelaRegistrationCert, LicenceCert = input.LicenceCert, TaxClearanceCert = input.TaxClearanceCert, EnquiryOrder = input.EnquiryOrder, ExportReturns = input.ExportReturns, ForestProduceRegCert = input.ForestProduceRegCert, AutholizedLetter = input.AutholizedLetter, SawMillerContract = input.SawMillerContract, MouCert = input.MouCert }; _exportAttachmentRepository.Insert(attachments); } catch (Exception ex) { throw new UserFriendlyException(ex.Message); }; }
public ActionResult addAttachments( HttpPostedFileBase BrelaRegistrationCert, HttpPostedFileBase LicenceCert, HttpPostedFileBase TaxClearanceCert, HttpPostedFileBase EnquiryOrder, HttpPostedFileBase ExportReturns, HttpPostedFileBase ForestProduceRegCert, HttpPostedFileBase AutholizedLetter, HttpPostedFileBase SawMillerContract, HttpPostedFileBase MouCert, int ExportDetailId ) { try { var attachments = new CreateExportAttachment(); attachments.ExportDetailId = ExportDetailId; if (BrelaRegistrationCert != null && BrelaRegistrationCert.ContentLength > 0) { string _FileName = Path.GetFileName(BrelaRegistrationCert.FileName); string _savedpath = Guid.NewGuid() + "-" + _FileName; string _path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), _savedpath); attachments.BrelaRegistrationCert = _savedpath; BrelaRegistrationCert.SaveAs(_path); } if (LicenceCert != null && LicenceCert.ContentLength > 0) { string _FileName = Path.GetFileName(LicenceCert.FileName); string _savedpath = Guid.NewGuid() + "-" + _FileName; string _path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), _savedpath); attachments.LicenceCert = _savedpath; LicenceCert.SaveAs(_path); } if (TaxClearanceCert != null && TaxClearanceCert.ContentLength > 0) { string _FileName = Path.GetFileName(TaxClearanceCert.FileName); string _savedpath = Guid.NewGuid() + "-" + _FileName; string _path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), _savedpath); attachments.TaxClearanceCert = _savedpath; TaxClearanceCert.SaveAs(_path); } if (EnquiryOrder != null && EnquiryOrder.ContentLength > 0) { string _FileName = Path.GetFileName(EnquiryOrder.FileName); string _savedpath = Guid.NewGuid() + "-" + _FileName; string _path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), _savedpath); attachments.EnquiryOrder = _savedpath; EnquiryOrder.SaveAs(_path); } if (ExportReturns != null && ExportReturns.ContentLength > 0) { string _FileName = Path.GetFileName(ExportReturns.FileName); string _savedpath = Guid.NewGuid() + "-" + _FileName; string _path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), _savedpath); attachments.ExportReturns = _savedpath; ExportReturns.SaveAs(_path); } if (ForestProduceRegCert != null && ForestProduceRegCert.ContentLength > 0) { string _FileName = Path.GetFileName(ForestProduceRegCert.FileName); string _savedpath = Guid.NewGuid() + "-" + _FileName; string _path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), _savedpath); attachments.ForestProduceRegCert = _savedpath; ForestProduceRegCert.SaveAs(_path); } if (AutholizedLetter != null && AutholizedLetter.ContentLength > 0) { string _FileName = Path.GetFileName(AutholizedLetter.FileName); string _savedpath = Guid.NewGuid() + "-" + _FileName; string _path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), _savedpath); attachments.AutholizedLetter = _savedpath; AutholizedLetter.SaveAs(_path); } if (SawMillerContract != null && SawMillerContract.ContentLength > 0) { string _FileName = Path.GetFileName(SawMillerContract.FileName); string _savedpath = Guid.NewGuid() + "-" + _FileName; string _path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), _savedpath); attachments.SawMillerContract = _savedpath; SawMillerContract.SaveAs(_path); } if (MouCert != null && MouCert.ContentLength > 0) { string _FileName = Path.GetFileName(MouCert.FileName); string _savedpath = Guid.NewGuid() + "-" + _FileName; string _path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), _savedpath); attachments.MouCert = _savedpath; MouCert.SaveAs(_path); } _exportService.AddAttachments(attachments); ModelState.AddModelError("Success", "Files Uploaded Successfully!!"); return(RedirectToAction("Index", "Dashboard")); } catch (Exception ex) { ViewBag.ExportDetail = _exportService.getExportDetailById(ExportDetailId); ModelState.AddModelError("danger", ex.Message); return(View()); } }