public ActionResult Delete(int Id) { TestimonialHelper _helper = new TestimonialHelper(); TestimonialModel testimonialModel = new TestimonialModel(); testimonialModel = _helper.GetByID(Id); int count = _helper.Delete(testimonialModel); if (count == 0) { string filePath = Server.MapPath("~/Content/Resources/Testimonial") + "/" + testimonialModel.ImageFile; if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } // delete the file from s3 AwsS3Bucket.DeleteObject("resources/testimonial/" + testimonialModel.ImageFile); TempData["CommonMessage"] = AppLogic.setMessage(count, "Record deleted successfully."); } else { TempData["CommonMessage"] = AppLogic.setMessage(count, "Record deletion failed."); } return(RedirectToAction("Index")); }
public ActionResult Delete(long Id) { VendorHelper _helper = new VendorHelper(); VendorModel _model = new VendorModel(); _model = _helper.GetByID(Id); int count = _helper.Delete(_model); if (count == 0) { string initialPath = "resources/vendor/" + _model.VendorId; // for profile image string path = Server.MapPath("~/Content/Resources/Vendor/" + _model.VendorId + "/" + _model.ImageFile); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } // delete the file from s3 AwsS3Bucket.DeleteObject(initialPath + "/" + _model.ImageFile); // for Trade and business file path = Server.MapPath("~/Content/Resources/vendor/" + _model.VendorId + "/" + _model.TradeAndBusinessFile); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } // delete the file from s3 AwsS3Bucket.DeleteObject(initialPath + "/" + _model.TradeAndBusinessFile); TempData["CommonMessage"] = AppLogic.setMessage(count, "Record deleted successfully."); } else if (count == -2) { TempData["CommonMessage"] = AppLogic.setMessage(count, "Record deletion failed. Please delete all the related records first."); } else { TempData["CommonMessage"] = AppLogic.setMessage(count, "Record deletion failed."); } return(RedirectToAction("Index")); }
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 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 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 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)); }