public long AddNewAdminPMB(AdminPMBModel _model) { try { if (_model.Attachment != null) { Guid guid = Guid.NewGuid(); string ext = System.IO.Path.GetExtension(_model.Attachment.FileName); _model.AttachedFileActualName = _model.Attachment.FileName; _model.AttachedFileName = guid.ToString() + ext; } tblAdminPMB _pmbModel = new tblAdminPMB(); _pmbModel.AttachedFileActualName = _model.AttachedFileActualName; _pmbModel.AttachedFileName = _model.AttachedFileName; _pmbModel.Message = _model.Message; _pmbModel.CreatedBy = ClientSessionData.UserClientId; _pmbModel.CreatedFromIP = HttpContext.Current.Request.UserHostAddress; _pmbModel.CreatedOn = DateTime.UtcNow; _pmbModel.CreatedFor = _model.CreatedFor; _pmbModel.CreatedByUserType = ClientSessionData.ClientRoleName; _pmbModel.StrataBoardId = ClientSessionData.ClientStrataBoardId; using (StratasFairDBEntities context = new StratasFairDBEntities()) { context.tblAdminPMBs.Add(_pmbModel); _model.PMBId = context.SaveChanges(); } if (_model.PMBId > 0) { if (_model.Attachment != null) { string path = string.Empty; string initialPath = "resources/admin-owner-pmb/" + ClientSessionData.ClientStrataBoardId; // Add/Delete the new trade and business file and image details if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/pmbFiles/"))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/pmbFiles/")); } // save the file locally path = HttpContext.Current.Server.MapPath(Path.Combine("~/Content/" + initialPath + "/pmbFiles/" + _model.AttachedFileName)); _model.Attachment.SaveAs(path); // save the file on s3 AwsS3Bucket.CreateFile(initialPath + "/pmbFiles/" + _model.AttachedFileName, path); // delete the file locally if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } } return(_model.PMBId); } catch (Exception) { return(-1); } }
public ActionResult Edit(VendorModel _model) { try { // create a bucket if not exists string createBucket = AwsS3Bucket.CreateABucket(); if (ModelState.ContainsKey("ImageType")) { ModelState["ImageType"].Errors.Clear(); } var imageTypes = new string[] { "image/gif", "image/jpeg", "image/pjpeg", "image/png" }; int _maxLength = MaxLength * 1024 * 1024; if (_model.ImageType != null) { if (!imageTypes.Contains(_model.ImageType.ContentType)) { ModelState.AddModelError("ImageType", "Please choose either a GIF, JPG or PNG image."); } else if (_model.ImageType.ContentLength > _maxLength) { ModelState.AddModelError("ImageType", "Maximum allowed file size is " + MaxLength + " MB."); } //else if (imageTypes.Contains(_model.ImageType.ContentType) && _model.ImageType.ContentLength <= _maxLength) //{ // System.Drawing.Image img = System.Drawing.Image.FromStream(_model.ImageType.InputStream); // int height = img.Height; // int width = img.Width; // if (width > MaxImageWidth || height > MaxImageHeight) // { // ModelState.AddModelError("ImageType", "Maximum allowed file dimension is " + MaxImageWidth + "*" + MaxImageHeight); // } //} } if (ModelState.ContainsKey("TradeAndBusinessFileType")) { ModelState["TradeAndBusinessFileType"].Errors.Clear(); } int _maxFileLength = MaxFileLength * 1024 * 1024; if (_model.TradeAndBusinessFileType != null) { string AlllowedExtension = ".pdf"; List <string> extList = AlllowedExtension.Split(',').ToList <string>(); if (!extList.Contains(System.IO.Path.GetExtension(_model.TradeAndBusinessFileType.FileName))) { ModelState.AddModelError("TradeAndBusinessFileType", "Please choose only " + AlllowedExtension + " file."); } else if (_model.TradeAndBusinessFileType.ContentLength > _maxFileLength) { ModelState.AddModelError("TradeAndBusinessFileType", "Maximum allowed file size is " + MaxFileLength + " MB."); } } if (ModelState.IsValid) { VendorHelper _Helper = new VendorHelper(); long _vendorId = 0; int? _adminApproval = 0; string uniqueId = Guid.NewGuid().ToString(); string ext = string.Empty; string extFile = string.Empty; if (_model.TradeAndBusinessFileType != null) { extFile = System.IO.Path.GetExtension(_model.TradeAndBusinessFileType.FileName); _model.TradeAndBusinessFile = uniqueId + extFile; _model.ActualTradeAndBusinessFile = _model.TradeAndBusinessFileType.FileName; } if (_model.ImageType != null) { ext = System.IO.Path.GetExtension(_model.ImageType.FileName); _model.ImageFile = uniqueId + "_img" + ext; _model.ActualImageFile = _model.ImageType.FileName; } _adminApproval = _model.AdminApprovalPrev; _vendorId = _Helper.AddUpdate(_model); if (_vendorId > 0) { string initialPath = "resources/vendor/" + _vendorId; // Add/Delete the new trade and business file and image details string path = string.Empty; string oldfilePath = string.Empty; int fileMapped = -1; if (_model.ImageType != null) { // save the file locally if (!Directory.Exists(Server.MapPath("~/Content/" + initialPath + "/ProfilePicture/"))) { Directory.CreateDirectory(Server.MapPath("~/Content/" + initialPath + "/ProfilePicture/")); } // save the file locally path = Server.MapPath(Path.Combine("~/Content/" + initialPath + "/ProfilePicture/" + _model.ImageFile)); _model.ImageType.SaveAs(path); // save the file on s3 fileMapped = AwsS3Bucket.CreateFile(initialPath + "/ProfilePicture/" + _model.ImageFile, path); // delete the file locally if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } /*******************************************************************************/ // delete the old file locally oldfilePath = Server.MapPath("~/Content/Resources/Vendor/" + _vendorId + "/ProfilePicture/" + _model.OldImageFile); if (System.IO.File.Exists(oldfilePath)) { System.IO.File.Delete(oldfilePath); } // delete the old file from s3 AwsS3Bucket.DeleteObject(initialPath + "/ProfilePicture/" + _model.OldImageFile); /*******************************************************************************/ } if (_model.TradeAndBusinessFileType != null) { // save the file locally if (!Directory.Exists(Server.MapPath("~/Content/" + initialPath + "/TradeFile/"))) { Directory.CreateDirectory(Server.MapPath("~/Content/" + initialPath + "/TradeFile/")); } path = Server.MapPath("~/Content/Resources/Vendor/" + _vendorId + "/TradeFile/" + _model.TradeAndBusinessFile); _model.TradeAndBusinessFileType.SaveAs(path); // save the file on s3 fileMapped = AwsS3Bucket.CreateFile(initialPath + "/TradeFile/" + _model.TradeAndBusinessFile, path); // delete the file locally if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } // delete the old file locally oldfilePath = Server.MapPath("~/Content/Resources/Vendor/" + _vendorId + "/TradeFile/" + _model.OldTradeAndBusinessFile); if (System.IO.File.Exists(oldfilePath)) { System.IO.File.Delete(oldfilePath); } // delete the old file from s3 AwsS3Bucket.DeleteObject(initialPath + "/TradeFile/" + _model.OldTradeAndBusinessFile); } if (_model.AdminApproval == 2 && _adminApproval != 2) { SendVendorRejectedMail(_vendorId); } if (_model.AdminApproval == 1 && _adminApproval != 1) { SendVendorApprovedMail(_vendorId); } TempData["CommonMessage"] = AppLogic.setMessage(0, "Record updated successfully."); return(RedirectToAction("Index")); } else if (_vendorId == -1) { TempData["CommonMessage"] = AppLogic.setMessage(1, "Record already exists."); } else { TempData["CommonMessage"] = AppLogic.setMessage(2, "Error, Please try again."); } } } catch (Exception ex) { } ViewBag.DisciplineList = CommonData.GetDisciplineWithoutOtherList(); ViewBag.StatusList = AppLogic.BindDDStatus(Convert.ToInt32(_model.Status)); return(View(_model)); }
public JsonResult BulkUploadStrataOwner(HttpPostedFileBase FileUpload) { int result = 0; string strMsg = ""; try { if (FileUpload != null) { StrataOwnerModel strataboardModel = new StrataOwnerModel(); DataTable dt = new DataTable(); if (FileUpload.ContentLength > 0) { string fileName = Path.GetFileName(FileUpload.FileName); string PhysicalPath = "~/Content/Resources/BulkUpload/"; if (!Directory.Exists(Server.MapPath(PhysicalPath))) { Directory.CreateDirectory(Server.MapPath(PhysicalPath)); } string path = Path.Combine(Server.MapPath("~/Content/Resources/BulkUpload/"), fileName); string extension = Path.GetExtension(FileUpload.FileName); string savedFileName = "~/Content/Resources/BulkUpload/" + fileName; FileUpload.SaveAs(path); if (extension == ".xls" || extension == ".xlsx" || extension == ".csv") { if (extension == ".xls" || extension == ".xlsx") { //The below code reads the excel file. var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0;", Server.MapPath(savedFileName)); var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString); var ds = new DataSet(); adapter.Fill(ds, "results"); dt = ds.Tables["results"]; } else if (extension == ".csv") { dt = ProcessCSV(path); } foreach (DataRow row in dt.Rows) { strataboardModel.FirstName = row["First Name"].ToString(); strataboardModel.LastName = row["Last Name"].ToString(); strataboardModel.Email = row["Email Address"].ToString(); strataboardModel.UnitNumber = row["Unit Number"].ToString(); //Data saved to database. if (!string.IsNullOrEmpty(strataboardModel.FirstName) && !string.IsNullOrEmpty(strataboardModel.LastName) && !string.IsNullOrEmpty(strataboardModel.Email) && !string.IsNullOrEmpty(strataboardModel.UnitNumber)) { strataOwnerHelper.AddUpdate(strataboardModel); result++; } } if (result > 0) { int fileMapped = AwsS3Bucket.CreateFile("resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/ImportUsers/" + FileUpload.FileName, path); System.IO.File.Delete(path); strMsg = "Bulk upload of strata owners are successfully saved."; } else { System.IO.File.Delete(path); strMsg = "Uploaded file is empty. please fill data before upload."; } } else { strMsg = "Please upload only Excel (.xls, .xlsx) OR Csv(.csv) File"; } } else { strMsg = "Uploaded file is empty. please fill data before upload."; } } else { strMsg = "Please upload a file before submit."; } } catch (Exception ex) { strMsg = "Bulk upload failed due to " + ex.Message; } return(Json(new { counter = result, msg = strMsg }, JsonRequestBehavior.AllowGet)); }
public ActionResult MyProfile(ClientLogOnModel model) { if (ClientSessionData.UserClientId != 0) { try { var imageTypes = new string[] { "image/png", "image/jpeg", "image/pjpeg" }; int _maxLength = MaxProfileImageLength * 1024 * 1024; ModelState.Remove("ImageType"); if (model.ImageType != null) { if (!imageTypes.Contains(model.ImageType.ContentType)) { ModelState.AddModelError("ImageType", "Please choose either a JPG or PNG image."); } else if (model.ImageType.ContentLength > _maxLength) { ModelState.AddModelError("ImageType", "Maximum allowed file size is " + MaxProfileImageLength + " MB."); } else if (imageTypes.Contains(model.ImageType.ContentType) && model.ImageType.ContentLength <= _maxLength) { System.Drawing.Image img = System.Drawing.Image.FromStream(model.ImageType.InputStream); int height = img.Height; int width = img.Width; if (width > MaxProfileImageWidth || height > MaxProfileImageHeight) { ModelState.AddModelError("ImageType", "Maximum allowed file dimension is " + MaxProfileImageWidth + "*" + MaxProfileImageHeight); } } } if (ModelState.IsValidField("FirstName") && ModelState.IsValidField("LastName")) { int result = 0; if (model.ImageType != null) { string ext = System.IO.Path.GetExtension(model.ImageType.FileName); model.ProfilePicture = Guid.NewGuid() + ext; string path = "~/Content/Resources/Stratabaord/" + ClientSessionData.ClientStrataBoardId + "/profileimages/"; if (!Directory.Exists(Server.MapPath(path))) { Directory.CreateDirectory(Server.MapPath(path)); } string Mappedpath = Server.MapPath(path + model.ProfilePicture); result = clientLoginHelper.UpdateProfile(model, false); if (result == 1) { // save the file locally model.ImageType.SaveAs(Mappedpath); // save the file on s3 int fileMapped = AwsS3Bucket.CreateFile("resources/stratabaord/" + ClientSessionData.ClientStrataBoardId + "/profileimages/" + model.ProfilePicture, Mappedpath); // delete the file locally if (System.IO.File.Exists(Mappedpath)) { System.IO.File.Delete(Mappedpath); } string OldProfilePath = Server.MapPath(path + model.OldProfilePicture); if (System.IO.File.Exists(OldProfilePath)) { System.IO.File.Delete(OldProfilePath); } // delete the old file from s3 AwsS3Bucket.DeleteObject("resources/stratabaord/" + ClientSessionData.ClientStrataBoardId + "/profileimages/" + model.OldProfilePicture); TempData["CommonMessage"] = AppLogic.setMessage(result, "Record updated successfully."); return(RedirectToAction("Index")); } } else { result = clientLoginHelper.UpdateProfile(model, false); } if (result == 1) { model.Message = "Profile updated successfully!"; } else { model.Message = "Profile updation failed due to Session Expired!"; } } } catch (Exception ex) { new AppError().LogMe(ex); model.Message = "Profile Updation Failed"; return(View(model)); } return(Redirect(Url.Content("~/" + ClientSessionData.ClientPortalLink + "/settings/myprofile"))); } else { return(View(model)); } }
public ActionResult CompleteProfile(ClientLogOnModel model, HttpPostedFileBase file) { model.ImageType = file; if (ClientSessionData.UserClientId != 0) { try { var imageTypes = new string[] { "image/png", "image/jpeg", "image/pjpeg" }; int _maxLength = MaxProfileImageLength * 1024 * 1024; ModelState.Remove("ImageType"); if (model.ImageType != null) { if (!imageTypes.Contains(model.ImageType.ContentType)) { ModelState.AddModelError("ImageType", "Please choose either a JPG or PNG image."); } else if (model.ImageType.ContentLength > _maxLength) { ModelState.AddModelError("ImageType", "Maximum allowed file size is " + MaxProfileImageLength + " MB."); } //else if (imageTypes.Contains(model.ImageType.ContentType) && model.ImageType.ContentLength <= _maxLength) //{ // System.Drawing.Image img = System.Drawing.Image.FromStream(model.ImageType.InputStream); // int height = img.Height; // int width = img.Width; // if (width > MaxProfileImageWidth || height > MaxProfileImageHeight) // { // ModelState.AddModelError("ImageType", "Maximum allowed file dimension is " + MaxProfileImageWidth + "*" + MaxProfileImageHeight); // } //} } ModelState.Remove("Email"); ModelState.Remove("Password"); int result = 0; if (ModelState.IsValid) { if (model.ImageType != null) { string ext = System.IO.Path.GetExtension(model.ImageType.FileName); model.ProfilePicture = Guid.NewGuid() + ext; string path = "~/Content/Resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/profileimages/"; if (!Directory.Exists(Server.MapPath(path))) { Directory.CreateDirectory(Server.MapPath(path)); } string Mappedpath = Server.MapPath(path + model.ProfilePicture); result = clientLoginHelper.CompleteProfile(model); if (result == 1) { // save the file locally model.ImageType.SaveAs(Mappedpath); // save the file on s3 int fileMapped = AwsS3Bucket.CreateFile("resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/profileimages/" + model.ProfilePicture, Mappedpath); // delete the file locally if (System.IO.File.Exists(Mappedpath)) { System.IO.File.Delete(Mappedpath); } string OldProfilePath = Server.MapPath(path + model.OldProfilePicture); if (System.IO.File.Exists(OldProfilePath)) { System.IO.File.Delete(OldProfilePath); } // delete the old file from s3 AwsS3Bucket.DeleteObject("resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/profileimages/" + model.OldProfilePicture); } } else { result = clientLoginHelper.CompleteProfile(model); } if (result == 1) { ClientSessionData.ClientIsProfileCompleted = true; return(Redirect(Url.Content("~/" + ClientSessionData.ClientPortalLink + "/dashboard"))); } else { TempData["CommonMessage"] = AppLogic.setFrontendMessage(2, "Profile Completion Failed."); return(View(model)); } } else { return(View(model)); } } catch (Exception ex) { new AppError().LogMe(ex); TempData["CommonMessage"] = AppLogic.setFrontendMessage(2, "Something wrong! Profile Completion Failed."); return(View(model)); } } else { return(View(model)); } }
public JsonResult AddTopic(ForumModel model) { int result = 0; string strMsg = ""; try { if (String.IsNullOrEmpty(model.Topic) || model.Topic.Trim() == "") { result = -3; strMsg = "Topic required."; } else if (String.IsNullOrEmpty(model.TopicContent) || model.TopicContent.Trim() == "") { result = -4; strMsg = "Comment required."; } if (model.ImageType != null) { string ext = Path.GetExtension(model.ImageType.FileName).ToLower(); if (ext != ".jpg" && ext != ".jpeg" && ext != ".pdf" && ext != ".png" && ext != ".xlsx" && ext != ".docx" && ext != ".pptx") { result = -1; strMsg = "Please upload only .jpg, .png, .pdf, .pptx, .docx or .xlsx File"; } else { Guid guid = Guid.NewGuid(); model.UploadedFileActualName = model.ImageType.FileName; model.UploadedFileName = guid.ToString() + ext; string path = string.Empty; string initialPath = "~/content/resources/strataboard"; if (!Directory.Exists(Server.MapPath(initialPath))) { Directory.CreateDirectory(Server.MapPath(initialPath)); } initialPath = initialPath + "/" + ClientSessionData.ClientStrataBoardId; if (!Directory.Exists(Server.MapPath(initialPath))) { Directory.CreateDirectory(Server.MapPath(initialPath)); } initialPath = initialPath + "/myforum"; if (!Directory.Exists(Server.MapPath(initialPath))) { Directory.CreateDirectory(Server.MapPath(initialPath)); } // save the file locally path = Server.MapPath(Path.Combine(initialPath + "/" + model.UploadedFileName)); model.ImageType.SaveAs(path); // save the file on s3 int fileMapped = AwsS3Bucket.CreateFile("resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/myforum/" + model.UploadedFileName, path); if (fileMapped != 0) { result = -2; strMsg = "Error is uploading file in S3, Try again later."; } // delete the file locally if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } } if (result == 0) { ForumHelper helper = new ForumHelper(); string msg = helper.AddTopic(model); if (msg != "success") { strMsg = "Error: Try again later"; result = -3; } } } catch (Exception ex) { strMsg = "Exception: " + ex.Message; result = -5; } return(Json(new { counter = result, msg = strMsg }, JsonRequestBehavior.AllowGet)); }
public ActionResult EditGeneralInformation(GeneralInformationModel model, HttpPostedFileBase FileUpload1) { int result = 0; string strMsg = ""; try { var imageTypes = new string[] { "image/png", "image/jpg", "image/pjpeg", "application/pdf", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.openxmlformats-officedocument.presentationml.presentation", }; if (!imageTypes.Contains(FileUpload1.ContentType)) { strMsg = "User can add the file with extension (.jpg, .png, .pdf, .docx, .pptx, .xlsx)"; } else { if (ModelState.IsValid) { model.ActualUploadFile = System.IO.Path.GetFileName(FileUpload1.FileName); model.UploadFile = Guid.NewGuid() + System.IO.Path.GetExtension(FileUpload1.FileName); result = noticeBoardHelper.AddUpdateGeneralInformation(model); string path = "~/Content/Resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/generalinformation/"; if (!Directory.Exists(Server.MapPath(path))) { Directory.CreateDirectory(Server.MapPath(path)); } string Mappedpath = Server.MapPath(path + model.UploadFile); if (result == 1) { // save the file locally FileUpload1.SaveAs(Mappedpath); // save the file on s3 int fileMapped = AwsS3Bucket.CreateFile("resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/generalinformation/" + model.UploadFile, Mappedpath); // delete the file locally if (System.IO.File.Exists(Mappedpath)) { System.IO.File.Delete(Mappedpath); } string OldProfilePath = Server.MapPath(path + model.OldUploadFile); if (System.IO.File.Exists(OldProfilePath)) { System.IO.File.Delete(OldProfilePath); } // delete the old file from s3 AwsS3Bucket.DeleteObject("resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/generalinformation/" + model.OldUploadFile); strMsg = "General Information updated successfully."; } else { strMsg = "General Information updation failed."; } } } } catch { } return(Json(new { result = result, Msg = strMsg })); }
public long AddNewVendor(VendorModel objectModel, HttpPostedFileBase image, HttpPostedFileBase tradeFile) { long _vendorId = -2; if (!IsEmailExists(objectModel.EmailId)) { if (image != null) { Guid g = Guid.NewGuid(); objectModel.ActualImageFile = image.FileName; objectModel.ImageFile = g.ToString() + Path.GetExtension(image.FileName); } if (tradeFile != null) { Guid g2 = Guid.NewGuid(); objectModel.ActualTradeAndBusinessFile = tradeFile.FileName; objectModel.TradeAndBusinessFile = g2.ToString() + Path.GetExtension(tradeFile.FileName); } tblVendor tblVendorDb = new tblVendor(); tblVendorDb.VendorName = objectModel.VendorName; tblVendorDb.EmailId = objectModel.EmailId; tblVendorDb.DisciplineId = objectModel.DisciplineId; tblVendorDb.OtherDisciplineName = objectModel.OtherDisciplineName; tblVendorDb.MobileNumber = objectModel.MobileNumber; tblVendorDb.CompanyBrief = objectModel.CompanyBrief; tblVendorDb.TradeAndBusinessFile = objectModel.TradeAndBusinessFile; tblVendorDb.ActualTradeAndBusinessFile = objectModel.ActualTradeAndBusinessFile; tblVendorDb.ImageFile = objectModel.ImageFile; tblVendorDb.ActualImageFile = objectModel.ActualImageFile; tblVendorDb.AdminApproval = 0; tblVendorDb.Status = 1; Encrypt64 enc = new Encrypt64(); tblVendorDb.Password = enc.Encrypt(AppLogic.GenerateRandomString(8)); tblVendorDb.CreatedOn = DateTime.UtcNow; tblVendorDb.CreatedFromIp = HttpContext.Current.Request.UserHostAddress; using (StratasFairDBEntities context = new StratasFairDBEntities()) { context.tblVendors.Add(tblVendorDb); context.SaveChanges(); } _vendorId = tblVendorDb.VendorId; try { if (_vendorId > 0) { string path = string.Empty; int fileMapped = -1; string initialPath = "resources/vendor/" + _vendorId; if (image != null) { // Add/Delete the new trade and business file and image details if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/ProfilePicture/"))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/ProfilePicture/")); } // save the file locally path = HttpContext.Current.Server.MapPath(Path.Combine("~/Content/" + initialPath + "/ProfilePicture/" + objectModel.ImageFile)); image.SaveAs(path); // save the file on s3 fileMapped = AwsS3Bucket.CreateFile(initialPath + "/ProfilePicture/" + objectModel.ImageFile, path); // delete the file locally if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } if (tradeFile != null) { // Add/Delete the new trade and business file and image details if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/TradeFile/"))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/TradeFile/")); } // save the file locally path = HttpContext.Current.Server.MapPath(Path.Combine("~/Content/" + initialPath + "/TradeFile/" + objectModel.TradeAndBusinessFile)); tradeFile.SaveAs(path); // save the file on s3 fileMapped = AwsS3Bucket.CreateFile(initialPath + "/TradeFile/" + objectModel.TradeAndBusinessFile, path); //delete the file locally if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } } } catch (Exception ex) { new AppError().LogMe(ex); // any error is there } return(_vendorId); } else { return(-3); } }
public ActionResult Edit(ManageAdvertisementModel advertisementModel) { var imageTypes = new string[] { "image/png", "image/jpeg", "image/pjpeg" }; int _maxLength = MaxLength * 1024 * 1024; ModelState.Remove("ImageType"); if (advertisementModel.ImageType != null) { if (!imageTypes.Contains(advertisementModel.ImageType.ContentType)) { ModelState.AddModelError("ImageType", "Please choose either a JPG or PNG image."); } else if (advertisementModel.ImageType.ContentLength > _maxLength) { ModelState.AddModelError("ImageType", "Maximum allowed file size is " + MaxLength + " MB."); } else if (imageTypes.Contains(advertisementModel.ImageType.ContentType) && advertisementModel.ImageType.ContentLength <= _maxLength) { System.Drawing.Image img = System.Drawing.Image.FromStream(advertisementModel.ImageType.InputStream); int height = img.Height; int width = img.Width; if (width > MaxImageWidth || height > MaxImageHeight) { ModelState.AddModelError("ImageType", "Maximum allowed file dimension is " + MaxImageWidth + "*" + MaxImageHeight); } } } if (ModelState.IsValid) { AdvertisementHelper advertisementHelper = new AdvertisementHelper(); int count = -1; if (advertisementModel.ImageType != null) { advertisementModel.ActualImageFile = advertisementModel.ImageType.FileName.ToString(); string ext = System.IO.Path.GetExtension(advertisementModel.ImageType.FileName); advertisementModel.ImageFile = Guid.NewGuid() + ext; string path = Server.MapPath("~/Content/Resources/Advertisement/" + advertisementModel.ImageFile); count = advertisementHelper.AddUpdate(advertisementModel); if (count == 0) { // save the file locally advertisementModel.ImageType.SaveAs(path); // save the file on s3 int fileMapped = AwsS3Bucket.CreateFile("resources/advertisement/" + advertisementModel.ImageFile, path); // delete the file locally if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } string filePath = Server.MapPath("~/Content/Resources/Advertisement") + "/" + advertisementModel.OldImageFile; if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } // delete the old file from s3 AwsS3Bucket.DeleteObject("resources/advertisement/" + advertisementModel.OldImageFile); TempData["CommonMessage"] = AppLogic.setMessage(count, "Record updated successfully."); return(RedirectToAction("Index")); } } else { count = advertisementHelper.AddUpdate(advertisementModel); } if (count == 0) { TempData["CommonMessage"] = AppLogic.setMessage(count, "Record updated successfully."); return(RedirectToAction("Index")); } else { TempData["CommonMessage"] = AppLogic.setMessage(count, "Error: Please try again."); ViewBag.StatusList = AppLogic.BindDDStatus(Convert.ToInt32(advertisementModel.Status)); return(View(advertisementHelper)); } } ViewBag.StatusList = AppLogic.BindDDStatus(Convert.ToInt32(advertisementModel.Status)); return(View(advertisementModel)); }
public ActionResult Add(TestimonialModel testimonialModel) { // create a bucket if not exists string createBucket = AwsS3Bucket.CreateABucket(); if (ModelState.ContainsKey("ImageType")) { ModelState["ImageType"].Errors.Clear(); } var imageTypes = new string[] { "image/png", "image/jpeg", "image/pjpeg" }; int _maxLength = MaxLength * 1024 * 1024; if (testimonialModel.ImageType == null || testimonialModel.ImageType.ContentLength == 0) { ModelState.AddModelError("ImageType", "Image is required"); } else if (!imageTypes.Contains(testimonialModel.ImageType.ContentType)) { ModelState.AddModelError("ImageType", "Please choose either a JPG or PNG image."); } else if (testimonialModel.ImageType.ContentLength > _maxLength) { ModelState.AddModelError("ImageType", "Maximum allowed file size is " + MaxLength + " MB."); } //else if (testimonialModel.ImageType != null && imageTypes.Contains(testimonialModel.ImageType.ContentType) && testimonialModel.ImageType.ContentLength <= _maxLength) //{ // System.Drawing.Image img = System.Drawing.Image.FromStream(testimonialModel.ImageType.InputStream); // int height = img.Height; // int width = img.Width; // if (width > MaxImageWidth || height > MaxImageHeight) // { // ModelState.AddModelError("ImageType", "Maximum allowed file dimension is " + MaxImageWidth + "*" + MaxImageHeight); // } //} if (ModelState.IsValid) { TestimonialHelper _Helper = new TestimonialHelper(); if (testimonialModel.ImageType != null) { string ext = System.IO.Path.GetExtension(testimonialModel.ImageType.FileName); testimonialModel.ActualImageFile = testimonialModel.ImageType.FileName.ToString(); testimonialModel.ImageFile = Guid.NewGuid() + ext; int count = _Helper.AddUpdate(testimonialModel); if (count == 0) { string initialPath = "resources/testimonial"; // save the file locally string path = Server.MapPath("~/Content/Resources/Testimonial/" + testimonialModel.ImageFile); testimonialModel.ImageType.SaveAs(path); // save the file on s3 int fileMapped = AwsS3Bucket.CreateFile(initialPath + "/" + testimonialModel.ImageFile, path); // delete the file locally if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } TempData["CommonMessage"] = AppLogic.setMessage(count, "Record added successfully."); return(RedirectToAction("Index")); } else if (count == 1) { TempData["CommonMessage"] = AppLogic.setMessage(count, "Record already exists."); ViewBag.StatusList = AppLogic.BindDDStatus(1); return(View(testimonialModel)); } else { ViewBag.StatusList = AppLogic.BindDDStatus(1); TempData["CommonMessage"] = AppLogic.setMessage(count, "Error, Please try again."); return(View(testimonialModel)); } } } ViewBag.StatusList = AppLogic.BindDDStatus(1); return(View(testimonialModel)); }