public JsonResult Delete(int id) { try { var currentUser = GetAuthenticatedUser(); var entity = _context.Product.Single(x => x.StatusId != ProductStatus.Deleted.Id && x.Id == id); if (!string.IsNullOrEmpty(entity.FileId)) { AsefianFileContextHelper.DeleteFile(entity.FileId, entity.FileName, currentUser.id, "admin", "product"); } entity.StatusId = ProductStatus.Deleted.Id; entity.ModifyUserId = currentUser.id; entity.ModifyDate = GetDatetime(); entity.ModifyIp = GetCurrentIp(); _context.SaveChanges(); return(Success("محصول با موفقیت حذف شد.")); } catch (Exception ex) { return(ServerError(ex)); } }
public JsonResult RemoveFile(string id, string fileName) { try { var currentUser = GetAuthenticatedUser(); AsefianFileContextHelper.DeleteFile(id, fileName, currentUser.id); return(Success("فایل با موفقیت حذف شد.")); } catch (Exception ex) { return(ServerError(ex)); } }
/// <summary> /// تایید فایل تصاویر در کد های اچ تی ام ال /// </summary> /// <param name="text">متن اچ تی ام ال</param> protected void DeleteHtmlImageFile(string text) { if (string.IsNullOrEmpty(text)) { return; } var currentUser = GetAuthenticatedUser(); foreach (Match item in Regex.Matches(text, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase)) { string matchString = item.Groups[1].Value; var imageParts = matchString.Split('/'); AsefianFileContextHelper.DeleteFile(imageParts[3], imageParts[4], currentUser.id); } }
public JsonResult AddProductImage(AddProductImageViewModel model) { var currentUser = GetAuthenticatedUser(); try { var entity = _context.Product.Single(x => x.Id == model.id); if (Request.Files.Count > 0) { if (!string.IsNullOrEmpty(entity.FileId)) { AsefianFileContextHelper.DeleteFile(entity.FileId, entity.FileName, currentUser.id, "admin", "product"); } var fileEntity = AsefianFileContextHelper.Save(Request.Files[0], currentUser.id, GetCurrentIp(), "admin", "product"); model.productFileId = fileEntity.id; model.productFileName = fileEntity.fileName; } else if (string.IsNullOrEmpty(model.productFileId) && !string.IsNullOrEmpty(entity.FileId)) { if (!string.IsNullOrEmpty(entity.FileId)) { AsefianFileContextHelper.DeleteFile(entity.FileId, entity.FileName, currentUser.id, "admin", "Product"); } } entity.FileId = model.productFileId; entity.FileName = model.productFileName; _context.SaveChanges(); var data = new { id = entity.Id, fileName = entity.FileName, fileId = entity.FileId }; return(Success("Done", data)); } catch (Exception ex) { return(ServerError(ex)); } }
public JsonResult RemoveGalleryFile(int id) { try { var currentUser = GetAuthenticatedUser(); var file = _context.ProductFile.Single(x => x.Id == id); if (file != null) { AsefianFileContextHelper.DeleteFile(file.FileId, file.FileName, currentUser.id); file.StatusId = ProductFileStatus.Deleted.Id; file.ModifyUserId = currentUser.id; file.ModifyDate = GetDatetime(); file.ModifyIp = GetCurrentIp(); _context.SaveChanges(); } return(Success("فایل با موفقیت حذف شد.")); } catch (Exception ex) { return(ServerError(ex)); } }
public JsonResult Save(SpecialProjectViewModel model) { try { if (string.IsNullOrEmpty(model.fileId) && Request.Files.Count == 0) { return(Error("وارد کردن فایل تصویر الزامی است.")); } var currentUser = GetAuthenticatedUser(); if (model.id != null && model.id > 0) { var entity = _context.SpecialProject.Single(x => x.StatusId != SpecialProjectStatus.Deleted.Id && x.Id == model.id); if (Request.Files.Count > 0) { if (!string.IsNullOrEmpty(entity.FileId)) { AsefianFileContextHelper.DeleteFile(entity.FileId, entity.FileName, currentUser.id, "admin", "mainPage"); } var fileEntity = AsefianFileContextHelper.Save(Request.Files[0], currentUser.id, GetCurrentIp(), "admin", "mainPage"); model.fileId = fileEntity.id; model.fileName = fileEntity.fileName; } else if (string.IsNullOrEmpty(model.fileId) && !string.IsNullOrEmpty(entity.FileId)) { if (!string.IsNullOrEmpty(entity.FileId)) { AsefianFileContextHelper.DeleteFile(entity.FileId, entity.FileName, currentUser.id, "admin", "mainPage"); } } entity.Order = model.order; entity.FileId = model.fileId; entity.FileName = model.fileName; entity.Sku = model.translations.Single(x => x.languageId == Language.Persian.Id).title.ToStandardPersian(); entity.StatusId = model.statusId; entity.ModifyUserId = currentUser.id; entity.ModifyDate = GetDatetime(); entity.ModifyIp = GetCurrentIp(); model.translations.ForEach(item => { var entityItem = entity.TranslationList.SingleOrDefault(x => x.LanguageId == item.languageId); if (entityItem != null) { entityItem.Title = item.title.ToStandardPersian(); entityItem.Description = item.description.ToStandardPersian(); } else { entityItem = new SpecialProjectTranslation() { SpecialProjectId = entity.Id, LanguageId = item.languageId, Title = item.title, Description = item.description.ToStandardPersian(), }; _context.SpecialProjectTranslation.Add(entityItem); } }); _context.SaveChanges(); return(Success("اطلاعات پروژه های خاص با موفقیت ویرایش شد.")); } else { if (Request.Files.Count > 0) { var fileEntity = AsefianFileContextHelper.Save(Request.Files[0], currentUser.id, GetCurrentIp(), "admin", "mainPage"); model.fileId = fileEntity.id; model.fileName = fileEntity.fileName; } else { model.fileId = null; model.fileName = null; } var entity = new SpecialProject() { Order = model.order, FileId = model.fileId, FileName = model.fileName, Sku = model.translations.Single(x => x.languageId == Language.Persian.Id).title.ToStandardPersian(), StatusId = model.statusId, CreateUserId = currentUser.id, ModifyUserId = currentUser.id, CreateDate = GetDatetime(), ModifyDate = GetDatetime(), CreateIp = GetCurrentIp(), ModifyIp = GetCurrentIp() }; _context.SpecialProject.Add(entity); model.translations.ForEach(item => { var entityItem = entity.TranslationList.SingleOrDefault(x => x.LanguageId == item.languageId); if (entityItem != null) { entityItem.Title = item.title.ToStandardPersian(); entityItem.Description = item.description.ToStandardPersian(); } else { entityItem = new SpecialProjectTranslation() { SpecialProjectId = entity.Id, LanguageId = item.languageId, Title = item.title, Description = item.description.ToStandardPersian(), }; _context.SpecialProjectTranslation.Add(entityItem); } }); _context.SaveChanges(); return(Success("پروژه های خاص با موفقیت ایجاد شد.")); } } catch (Exception ex) { return(ServerError(ex)); } }
public JsonResult Save(NewsViewModel model) { var currentUser = GetAuthenticatedUser(); try { DateTime?expiredDate = null; if (!string.IsNullOrEmpty(model.PersianExpiredDate)) { expiredDate = DateUtility.GetDateTime(model.PersianExpiredDate); } if (model.id != null && model.id > 0) { if (string.IsNullOrEmpty(model.fileId) && Request.Files.Count == 0) { return(Error("وارد کردن تصویر الزامی است.")); } var entity = _context.News.Single(x => x.StatusId != NewsStatus.Deleted.Id && x.Id == model.id); if (Request.Files.Count > 0) { if (!string.IsNullOrEmpty(entity.FileId)) { AsefianFileContextHelper.DeleteFile(entity.FileId, entity.FileName, currentUser.id, "admin", "news"); } var fileEntity = AsefianFileContextHelper.Save(Request.Files[0], currentUser.id, GetCurrentIp(), "admin", "news"); model.fileId = fileEntity.id; model.fileName = fileEntity.fileName; } else if (string.IsNullOrEmpty(model.fileId) && !string.IsNullOrEmpty(entity.FileId)) { if (!string.IsNullOrEmpty(entity.FileId)) { AsefianFileContextHelper.DeleteFile(entity.FileId, entity.FileName, currentUser.id, "admin", "news"); } } entity.Sku = model.translations.Single(x => x.languageId == Language.Persian.Id).title.ToStandardPersian(); entity.FileId = model.fileId; entity.FileName = model.fileName; entity.PublishDate = string.IsNullOrEmpty(model.PersianPublishDate) ? GetDatetime() : DateUtility.GetDateTime(model.PersianPublishDate); entity.ExpiredDate = expiredDate; entity.StatusId = model.statusId; entity.ModifyUserId = currentUser.id; entity.ModifyDate = GetDatetime(); entity.ModifyIp = GetCurrentIp(); model.translations.ForEach(item => { var entityItem = entity.TranslationList.SingleOrDefault(x => x.LanguageId == item.languageId); if (entityItem != null) { entityItem.Title = item.title?.ToStandardPersian(); entityItem.AbstractText = item.abstractText?.ToStandardPersian(); entityItem.Text = item.text?.ToStandardPersian(); entityItem.Keywords = item.keywords?.ToStandardPersian(); } else { entityItem = new NewsTranslation() { NewsId = entity.Id, LanguageId = item.languageId, Title = item.title.ToStandardPersian(), AbstractText = item.abstractText?.ToStandardPersian(), Text = item.text?.ToStandardPersian(), Keywords = item.keywords?.ToStandardPersian(), }; _context.NewsTranslation.Add(entityItem); } }); _context.SaveChanges(); // تایید تمام فایل های جدید ذخیره شده در نقد و بررسی //VerifyHtmlImageFile(entity.Text); return(Success("اطلاعات خبر با موفقیت ویرایش شد.")); } else { if (Request.Files.Count > 0) { var fileEntity = AsefianFileContextHelper.Save(Request.Files[0], currentUser.id, GetCurrentIp(), "admin", "service"); model.fileId = fileEntity.id; model.fileName = fileEntity.fileName; } else { return(Error("وارد کردن تصویر خبر الزامی است.")); } var entity = new News() { Sku = model.translations.Single(x => x.languageId == Language.Persian.Id).title.ToStandardPersian(), FileId = model.fileId, FileName = model.fileName, View = model.view, PublishDate = string.IsNullOrEmpty(model.PersianPublishDate) ? GetDatetime() : DateUtility.GetDateTime(model.PersianPublishDate), ExpiredDate = expiredDate, StatusId = model.statusId, CreateUserId = currentUser.id, ModifyUserId = currentUser.id, CreateDate = GetDatetime(), ModifyDate = GetDatetime(), CreateIp = GetCurrentIp(), ModifyIp = GetCurrentIp() }; _context.News.Add(entity); model.translations.ForEach(item => { var entityItem = entity.TranslationList.SingleOrDefault(x => x.LanguageId == item.languageId); if (entityItem != null) { entityItem.Title = item.title?.ToStandardPersian(); entityItem.AbstractText = item.abstractText?.ToStandardPersian(); entityItem.Text = item.text?.ToStandardPersian(); entityItem.Keywords = item.keywords?.ToStandardPersian(); } else { entityItem = new NewsTranslation() { NewsId = entity.Id, LanguageId = item.languageId, Title = item.title.ToStandardPersian(), AbstractText = item.abstractText?.ToStandardPersian(), Text = item.text?.ToStandardPersian(), Keywords = item.keywords?.ToStandardPersian(), }; _context.NewsTranslation.Add(entityItem); } }); _context.SaveChanges(); // تایید تمام فایل های جدید ذخیره شده در نقد و بررسی //VerifyHtmlImageFile(entity.Text); return(Success("خبر با موفقیت ایجاد شد.")); } } catch (Exception ex) { return(ServerError(ex)); } }
public JsonResult Save(ServiceViewModel model) { var currentUser = GetAuthenticatedUser(); try { //if (string.IsNullOrEmpty(model.title)) //{ // return Error("وارد کردن عنوان اجباری است."); //} //if (string.IsNullOrEmpty(model.summary)) //{ // return Error("وارد کردن خلاصه خدمات اجباری است."); //} if (model.id != null && model.id > 0) { var entity = _context.Service.Single(x => x.StatusId != ServiceStatus.Deleted.Id && x.Id == model.id); if (Request.Files.Count > 0) { if (!string.IsNullOrEmpty(entity.FileId)) { AsefianFileContextHelper.DeleteFile(entity.FileId, entity.FileName, currentUser.id, "admin", "service"); } var fileEntity = AsefianFileContextHelper.Save(Request.Files[0], currentUser.id, GetCurrentIp(), "admin", "service"); model.fileId = fileEntity.id; model.fileName = fileEntity.fileName; } else if (string.IsNullOrEmpty(model.fileId) && !string.IsNullOrEmpty(entity.FileId)) { if (!string.IsNullOrEmpty(entity.FileId)) { AsefianFileContextHelper.DeleteFile(entity.FileId, entity.FileName, currentUser.id, "admin", "service"); } } entity.Order = model.order; entity.Sku = model.translations.Single(x => x.languageId == Language.Persian.Id).title.ToStandardPersian(); entity.FileId = model.fileId; entity.FileName = model.fileName; entity.StatusId = model.statusId; entity.ModifyUserId = currentUser.id; entity.ModifyDate = GetDatetime(); entity.ModifyIp = GetCurrentIp(); model.translations.ForEach(item => { var entityItem = entity.TranslationList.SingleOrDefault(x => x.LanguageId == item.languageId); if (entityItem != null) { entityItem.Title = item.title.ToStandardPersian(); entityItem.Description = item.description?.ToStandardPersian(); entityItem.Summary = item.summary?.ToStandardPersian(); } else { entityItem = new ServiceTranslation() { ServiceId = entity.Id, LanguageId = item.languageId, Title = item.title.ToStandardPersian(), Description = item.description?.ToStandardPersian(), Summary = item.summary?.ToStandardPersian() }; _context.ServiceTranslation.Add(entityItem); } }); _context.SaveChanges(); // تایید تمام فایل های جدید ذخیره شده در نقد و بررسی //VerifyHtmlImageFile(model.description); return(Success("اطلاعات خدمات با موفقیت ویرایش شد.")); } else { if (Request.Files.Count > 0) { var fileEntity = AsefianFileContextHelper.Save(Request.Files[0], currentUser.id, GetCurrentIp(), "admin", "service"); model.fileId = fileEntity.id; model.fileName = fileEntity.fileName; } else { model.fileId = null; model.fileName = null; } var entity = new Service() { Order = model.order, Sku = model.translations.Single(x => x.languageId == Language.Persian.Id).title.ToStandardPersian(), FileId = model.fileId, FileName = model.fileName, StatusId = model.statusId, CreateUserId = currentUser.id, ModifyUserId = currentUser.id, CreateDate = GetDatetime(), ModifyDate = GetDatetime(), CreateIp = GetCurrentIp(), ModifyIp = GetCurrentIp() }; _context.Service.Add(entity); model.translations.ForEach(item => { var entityItem = entity.TranslationList.SingleOrDefault(x => x.LanguageId == item.languageId); if (entityItem != null) { entityItem.Title = item.title.ToStandardPersian(); entityItem.Description = item.description?.ToStandardPersian(); entityItem.Summary = item.summary?.ToStandardPersian(); } else { entityItem = new ServiceTranslation() { ServiceId = entity.Id, LanguageId = item.languageId, Title = item.title.ToStandardPersian(), Description = item.description?.ToStandardPersian(), Summary = item.summary?.ToStandardPersian(), }; _context.ServiceTranslation.Add(entityItem); } }); _context.SaveChanges(); // تایید تمام فایل های جدید ذخیره شده در نقد و بررسی //VerifyHtmlImageFile(model.description); return(Success("خدمات با موفقیت ایجاد شد.")); } } catch (Exception ex) { return(ServerError(ex)); } }