private bool DataIsAccessable(DR_Requester requester, EntitySearch entitySearch) { if (requester.SkipSecurity) { return(true); } return(bizTableDrivedEntity.DataIsAccessable(requester, entitySearch.TableDrivedEntity1)); }
public bool DataIsAccessable(DR_Requester requester, DataLinkDefinition dataLink) { if (requester.SkipSecurity) { return(true); } if (!bizTableDrivedEntity.DataIsAccessable(requester, dataLink.TableDrivedEntity)) { return(false); } if (!bizEntityReport.DataIsAccessable(requester, dataLink.EntityDataItemReport.EntityReport)) { return(false); } //اینجا تیل چک نمیشه foreach (var tail in dataLink.DataLinkDefinition_EntityRelationshipTail) { if (!bizEntityRelationshipTail.DataIsAccessable(requester, tail.EntityRelationshipTail)) { return(false); } } return(true); }
private bool DataIsAccessable(DR_Requester requester, NavigationTree navigationTree) { if (navigationTree.TableDrivedEntityID != null) { if (!bizTableDrivedEntity.DataIsAccessable(requester, navigationTree.TableDrivedEntity)) { return(false); } } var category = (DatabaseObjectCategory)Enum.Parse(typeof(DatabaseObjectCategory), navigationTree.Category); if (category == DatabaseObjectCategory.Report) { if (!bizEntityReport.DataIsAccessable(requester, navigationTree.ItemIdentity)) { return(false); } } if (category == DatabaseObjectCategory.Letter) { if (!bizTableDrivedEntity.DataIsAccessable(requester, navigationTree.TableDrivedEntity, new List <SecurityAction>() { SecurityAction.LetterView, SecurityAction.LetterEdit })) { return(false); } } if (category == DatabaseObjectCategory.Archive) { if (!bizTableDrivedEntity.DataIsAccessable(requester, navigationTree.TableDrivedEntity, new List <SecurityAction>() { SecurityAction.ArchiveView, SecurityAction.ArchiveEdit })) { return(false); } } return(true); }
private void CheckPermissoinToEdit(DR_Requester requester, BaseResult result, List <QueryItem> allQueryItems) { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); bool permission = true; foreach (var entityGroup in allQueryItems.GroupBy(x => x.TargetEntity.ID)) { if (!bizTableDrivedEntity.DataIsAccessable(requester, entityGroup.Key, new List <SecurityAction>() { SecurityAction.EditAndDelete })) { permission = false; var entity = allQueryItems.First(x => x.TargetEntity.ID == entityGroup.Key).TargetEntity; result.Details.Add(ToResultDetail("عدم دسترسی", "عدم دسترسی ثبت به موجودیت" + " " + entity.Alias, "")); } else if (bizTableDrivedEntity.DataIsReadonly(requester, entityGroup.Key)) { permission = false; var entity = allQueryItems.First(x => x.TargetEntity.ID == entityGroup.Key).TargetEntity; result.Details.Add(ToResultDetail("عدم دسترسی", "عدم دسترسی ثبت به موجودیت" + " " + entity.Alias, "")); } } if (permission) { BizColumn bizColumn = new BizColumn(); foreach (var query in allQueryItems) { foreach (var column in query.EditingProperties) { if (!bizColumn.DataIsAccessable(requester, column.ColumnID) || column.IsHidden) { permission = false; result.Details.Add(ToResultDetail("عدم دسترسی", "عدم دسترسی به ستون" + " " + column.Column.Alias, "")); } else if (column.ValueIsChanged && (bizColumn.DataIsReadonly(requester, column.ColumnID) || column.IsReadonly)) { permission = false; result.Details.Add(ToResultDetail("عدم دسترسی", "عدم دسترسی ثبت به ستون" + " " + column.Column.Alias, "")); } } } } if (permission == false) { result.Result = Enum_DR_ResultType.ExceptionThrown; result.Message = "خطا در ثبت"; } }
internal bool DataIsAccessable(DR_Requester requester, Process process) { //if (!entity.IsEnabled) // return false; //else //{ //دسترسی به موجودیت هم چی شود if (process.TableDrivedEntityID != 0) { if (!bizTableDrivedEntity.DataIsAccessable(requester, process.TableDrivedEntity)) return false; else return true; } return true; //} }
//public bool UpdateArhiveItemTags(int iD, List<int> selectedTags) //{ // using (var context = new MyIdeaDataDBEntities()) // { // var item = context.ArchiveItem.First(x => x.ID == iD); // while (item.ArchiveItem_Tag.Any()) // context.ArchiveItem_Tag.Remove(item.ArchiveItem_Tag.First()); // foreach (var tagid in selectedTags) // { // item.ArchiveItem_Tag.Add(new ArchiveItem_Tag() { TagID = tagid }); // } // context.SaveChanges(); // return true; // } //} public bool UpdateArchiveItemFileBinary(DR_Requester requester, int iD, byte[] file) { using (var context = new MyIdeaDataDBEntities()) { //سکوریتی ثبت میتونه اینجا هم چک بشه var item = context.ArchiveItem.First(x => x.ID == iD); BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, item.MyDataItem.TableDrivedEntityID, new List <SecurityAction>() { SecurityAction.ArchiveEdit })) { throw new Exception("عدم دسترسی ثبت آرشیو"); } item.FileRepository1.Content = file; SetPossibleThumbnail(context, item, (Enum_ArchiveItemMainType)item.MainType, (Enum_ArchiveItemFileType)item.FileType, item.FileRepository1.Content, item.FileRepository1.FileName); context.SaveChanges(); return(true); } }
public bool UpdateMultipleArchiveItemInfo(DR_Requester requester, List <int> IDs, bool changeFolder, int?folderID, bool changeTagIDs, List <int> selectedTagIds) { using (var context = new MyIdeaDataDBEntities()) { //سکوریتی ثبت میتونه اینجا هم چک بشه //BizArchive bizArchive = new BizArchive(); foreach (var iD in IDs) { var item = context.ArchiveItem.First(x => x.ID == iD); BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, item.MyDataItem.TableDrivedEntityID, new List <SecurityAction>() { SecurityAction.ArchiveEdit })) { throw new Exception("عدم دسترسی ثبت آرشیو"); } if (changeFolder) { item.FolderID = folderID; } if (changeTagIDs) { //var entityArchiveTags = bizArchive.GetArchiveTags(item.MyDataItem.TableDrivedEntityID, true); //var entityTagIds = entityArchiveTags.Select(x => x.ID).ToList(); while (item.ArchiveItem_Tag.Any()) { context.ArchiveItem_Tag.Remove(item.ArchiveItem_Tag.First()); } foreach (var tagid in selectedTagIds) { item.ArchiveItem_Tag.Add(new ArchiveItem_Tag() { TagID = tagid }); } } } context.SaveChanges(); return(true); } }
private bool DataIsAccessable(DR_Requester requester, EntityGroup_Relationship ritem) { bool isvalid = true; if (ritem.EntityRelationshipTailID != null) { if (!bizEntityRelationshipTail.DataIsAccessable(requester, ritem.EntityRelationshipTail)) { isvalid = false; } } else if (ritem.EntityGroup.Process.TableDrivedEntity != null) { if (!bizTableDrivedEntity.DataIsAccessable(requester, ritem.EntityGroup.Process.TableDrivedEntity)) { isvalid = false; } } return(isvalid); }
public List <LetterRelationshipTailDTO> GetLetterRelationshipTails(DR_Requester requester, int entityID, bool withDetails) { List <LetterRelationshipTailDTO> result = new List <LetterRelationshipTailDTO>(); using (var projectContext = new DataAccess.MyProjectEntities()) { var list = projectContext.EntityLetterRelationshipTails.Where(x => x.TableDrivedEntityID == entityID); foreach (var item in list) { if (bizEntityRelationshipTail.DataIsAccessable(requester, item.EntityRelationshipTail)) { if (bizTableDrivedEntity.DataIsAccessable(requester, item.EntityRelationshipTail.TableDrivedEntity, new List <SecurityAction>() { SecurityAction.LetterView, SecurityAction.LetterEdit })) { result.Add(ToLetterRelationshipTailDTO(item, withDetails)); } } } } return(result); }
internal bool DataIsAccessable(DR_Requester requester, EntityReport entityReport) { //if (!entity.IsEnabled) // return false; //else //{ if (!bizTableDrivedEntity.DataIsAccessable(requester, entityReport.TableDrivedEntity)) { return(false); } var permission = securityHelper.GetAssignedPermissions(requester, entityReport.ID, false); if (permission.GrantedActions.Any(y => y == SecurityAction.NoAccess)) { return(false); } else { return(true); } //} }
public DataMenuResult GetDataMenu(DR_Requester requester, DP_DataView dataItem, int dataMenuSettingID) { DataMenuResult result = new DataMenuResult(); List <DataMenu> resultMenus = new List <DataMenu>(); result.DataMenus = resultMenus; var entityID = dataItem.TargetEntityID; var simpleEntity = bizTableDrivedEntity.GetSimpleEntity(requester, entityID); if (simpleEntity == null) { return(null); } DataMenuSettingDTO dataMenuSetting = null; if (dataMenuSettingID != 0) { dataMenuSetting = GetDataMenuSetting(requester, dataMenuSettingID, true); } else { dataMenuSetting = GetDefaultDataMenuSetting(requester, entityID, true); } if (dataMenuSetting != null) { result.DataMenuSettingName = dataMenuSetting.Name; } if (simpleEntity.IsView) { if (dataMenuSetting != null) { if (dataMenuSetting.RelationshipID != 0 && dataMenuSetting.TargetDataMenuSettingID != 0) { var relationship = bizRelationship.GetRelationship(dataMenuSetting.RelationshipID); var dataView = CreateDataView(requester, dataItem, relationship); return(GetDataMenu(requester, dataView, dataMenuSetting.TargetDataMenuSettingID)); } } //var fullEntity = bizTableDrivedEntity.GetTableDrivedEntity(requester, entityID, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithRelationships); //if (fullEntity.Relationships.Any()) //{ // foreach (var relationsip in fullEntity.Relationships) // { // var dataView = CreateDataView(dataItem, relationsip); // var menu = AddMenu(result, relationsip.Alias, "", DataMenuType.ViewRel); // menu.ViewRelTargetDataItem = dataView; // } //} } else { var dataEntryRootMenu = AddMenu(resultMenus, "نمایش/اصلاح داده", "", DataMenuType.Form, dataItem); //آرشیو داده // BizArchive bizArchive = new BizArchive(); if (bizTableDrivedEntity.DataIsAccessable(requester, entityID, new List <SecurityAction>() { SecurityAction.ArchiveView, SecurityAction.ArchiveEdit })) { var archiveRootMenu = AddMenu(resultMenus, "آرشیو", "", DataMenuType.Archive, dataItem); } //نامه های داده // BizLetterTemplate bizLetterTemplate = new BizLetterTemplate(); if (bizTableDrivedEntity.DataIsAccessable(requester, entityID, new List <SecurityAction>() { SecurityAction.LetterView, SecurityAction.LetterEdit })) { var letterRootMenu = AddMenu(resultMenus, "نامه ها", "", DataMenuType.Letter, dataItem); } //جریان کارهای مرتبط if (bizProcess.EntityHasAnyProcess(entityID)) { var workflowRootMenu = AddMenu(resultMenus, "جریان کار", "", DataMenuType.Workflow, dataItem); } ////لینک های داده //BizDataLink bizDataLink = new MyModelManager.BizDataLink(); //var datalinks = bizDataLink.GetDataLinkByEntitiyID(requester, entityID); //if (datalinks.Any()) //{ // var dataViewRootMenu = AddMenu(resultMenus, "لینک داده", "", DataMenuType.Folder,null); // foreach (var datalink in datalinks) // { // var datalinkMenu = AddMenu(dataViewRootMenu.SubMenus, datalink.ReportTitle, "", DataMenuType.DataLink, dataItem); // datalinkMenu.Datalink = datalink; // } //} //گزارشهای داده های مرتبط if (dataMenuSetting != null) { if (dataMenuSetting.SearchableReportRelationships.Any()) { var relationshipReportRootMenu = AddMenu(resultMenus, "گزارش داده های مرتبط", "", DataMenuType.Folder, null); foreach (var group in dataMenuSetting.SearchableReportRelationships.GroupBy(x => x.Group1 ?? "")) { DataMenu parentGroupMenu = GetGroupMenu(relationshipReportRootMenu, group.Key); foreach (var rel in group) { var menu = AddMenu(parentGroupMenu.SubMenus, rel.SearchableReportReport.ReportTitle, "", DataMenuType.RelationshipTailSearchableReport, dataItem); menu.SearchableReportRelationshipTail = rel; } } } //نمای داده های مرتبط if (dataMenuSetting.DataViewRelationships.Any()) { var dataViewRootMenu = AddMenu(resultMenus, "نمایش داده های مرتبط", "", DataMenuType.Folder, null); foreach (var group in dataMenuSetting.DataViewRelationships.GroupBy(x => x.Group1 ?? "")) { DataMenu parentGroupMenu = GetGroupMenu(dataViewRootMenu, group.Key); foreach (var rel in group) { var dataViewRelMenu = AddMenu(parentGroupMenu.SubMenus, rel.RelationshipTail.TargetEntityAlias, rel.RelationshipTail.EntityPath, DataMenuType.RelationshipTailDataView, dataItem); dataViewRelMenu.DataviewRelationshipTail = rel.RelationshipTail; dataViewRelMenu.TargetDataMenuSettingID = rel.TargetDataMenuSettingID; } } } if (dataMenuSetting.GridViewRelationships.Any()) { var gridViewRootMenu = AddMenu(resultMenus, "گرید داده های مرتبط", "", DataMenuType.Folder, null); foreach (var group in dataMenuSetting.GridViewRelationships.GroupBy(x => x.Group1 ?? "")) { DataMenu parentGroupMenu = GetGroupMenu(gridViewRootMenu, group.Key); foreach (var rel in group) { var gridViewRelMenu = AddMenu(parentGroupMenu.SubMenus, rel.RelationshipTail.TargetEntityAlias, rel.RelationshipTail.EntityPath, DataMenuType.RelationshipTailDataGrid, dataItem); gridViewRelMenu.GridviewRelationshipTail = rel.RelationshipTail; gridViewRelMenu.TargetDataMenuSettingID = rel.TargetDataMenuSettingID; } } } if (dataMenuSetting.DataItemReports.Any()) { var gridViewRootMenu = AddMenu(resultMenus, "گزارشات مورد داده", "", DataMenuType.Folder, null); foreach (var group in dataMenuSetting.DataItemReports.GroupBy(x => x.Group1 ?? "")) { DataMenu parentGroupMenu = GetGroupMenu(gridViewRootMenu, group.Key); foreach (var rel in group) { var gridViewRelMenu = AddMenu(parentGroupMenu.SubMenus, rel.EntityDataItemReport.ReportTitle, "", DataMenuType.DataItemReport, dataItem); gridViewRelMenu.DataItemReport = rel.EntityDataItemReport; } } } } } return(result); }
public LetterDeleteResult DeleteLetter(DR_Requester requester, int letterID) { LetterDeleteResult result = new LetterDeleteResult(); string exception = ""; using (var context = new MyIdeaDataDBEntities()) { //سکوریتی ثبت میتونه اینجا هم چک بشه //itemResult.ID = item.ID; var dbItem = context.Letter.First(x => x.ID == letterID); BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, dbItem.MyDataItem.TableDrivedEntityID, new List <SecurityAction>() { SecurityAction.LetterEdit })) { throw new Exception("عدم دسترسی ثبت نامه"); } try { if (dbItem.Letter1.Any()) { foreach (var item in dbItem.Letter1) { ResultDetail relatedItemException = new ResultDetail(); relatedItemException.Title = "دارای نامه مرتبط"; relatedItemException.Description = "نامه به شماره" + " " + item.LetterNumber + " " + "به تاریخ" + " " + item.LetterDate; result.Details.Add(relatedItemException); } result.Message = "به علت وجود نامه های مرتبط عملیات حذف امکان پذیر نمی باشد"; return(result); } context.Letter.Remove(dbItem); context.SaveChanges(); result.Result = true; result.Message = "عملیات حذف با موفقیت انجام شد"; } catch (Exception ex) { exception = ex.Message; ResultDetail itemResult = new ResultDetail(); itemResult.Title = "خطا"; itemResult.Description = "حذف نامه با شناسه" + " " + letterID + " " + "با خطا همراه بود"; itemResult.TechnicalDescription = ex.Message; result.Details.Add(itemResult); result.Message = "عملیات حذف با خطا همراه بود"; } finally { var logResult = bizLogManager.AddLog(GetDeleteItemDataLog(dbItem, exception), requester); if (!string.IsNullOrEmpty(logResult)) { ResultDetail logException = new ResultDetail(); logException.Title = "خطای ثبت لاگ"; logException.Description = "ثبت لاگ برای حذف فایل با شناسه" + " " + dbItem.ID + " " + "با خطا همراه بود"; logException.TechnicalDescription = logResult; result.Details.Add(logException); } } } return(result); }
public LetterResult UpdateLetter(LetterDTO message, DR_Requester requester) { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, message.DataItem.TargetEntityID, new List <SecurityAction>() { SecurityAction.LetterEdit })) { throw new Exception("عدم دسترسی ثبت نامه"); } LetterResult result = new LetterResult(); bool isNew = message.ID == 0; var letterSetting = GetLetterSetting(); if (letterSetting != null) { if (letterSetting.BeforeLetterSaveCodeID != 0) { var resultFunction = codeFunctionHandler.GetCodeFunctionResult(requester, letterSetting.BeforeLetterSaveCodeID, message); if (resultFunction.Exception != null) { var logResult = bizLogManager.AddLog(GetBeforeUpdateExceptionLog(message, resultFunction.Exception, isNew ? DataLogType.LetterInsert : DataLogType.LetterUpdate), requester); if (!string.IsNullOrEmpty(logResult)) { ResultDetail logException = new ResultDetail(); logException.Title = "خطای ثبت لاگ"; logException.Description = "خطای لاگ برای اقدام قبل از ثبت نامه"; logException.TechnicalDescription = logResult; result.Details.Add(logException); } result.Message = "اقدامات مرتبط قبل از ثبت نامه با خطا همراه بود"; return(result); } } } using (var letterModel = new MyIdeaDataDBEntities()) { try { var dbLetter = letterModel.Letter.FirstOrDefault(x => x.ID == message.ID); if (dbLetter == null) { dbLetter = new Letter(); dbLetter.CreationDate = DateTime.Now; dbLetter.UserID = requester.Identity; //var dataItemID = bizDataItem.GetOrCreateDataItem(message.DataItem); if (message.DataItem.DataItemID == 0) { dbLetter.MyDataItemID = bizDataItem.GetOrCreateDataItem(message.DataItem); message.DataItem.DataItemID = dbLetter.MyDataItemID; } else { dbLetter.MyDataItemID = message.DataItem.DataItemID; } } dbLetter.ID = message.ID; dbLetter.Desc = message.Desc; dbLetter.LetterNumber = message.LetterNumber; dbLetter.IsGeneratedOrSelected = message.IsGeneratedOrSelected; dbLetter.FromExternalSource = message.IsExternalOrInternal; dbLetter.ExternalSourceKey = message.ExternalCode; dbLetter.LetterNumber = message.LetterNumber; dbLetter.LetterDate = message.LetterDate; dbLetter.LetterTemplateID = message.LetterTemplateID == 0 ? (int?)null : message.LetterTemplateID; dbLetter.LetterTypeID = message.LetterTypeID; dbLetter.RelatedLetterID = message.RelatedLetterID == 0 ? (int?)null : message.RelatedLetterID; dbLetter.Title = message.Title; if (dbLetter.FileRepository == null) { if (message.AttechedFile != null && message.AttechedFile.Content != null) { dbLetter.FileRepository = bizFileRepository.ToFileRepository(letterModel, message.AttechedFile); } } if (dbLetter.ID == 0) { letterModel.Letter.Add(dbLetter); } letterModel.SaveChanges(); message.ID = dbLetter.ID; result.SavedID = dbLetter.ID; result.Result = true; } catch (Exception ex) { result.Result = false; result.Message = ex.Message; } finally { var logResult = bizLogManager.AddLog(GetUpdateLetterDataLog(message, result.Message, isNew ? DataLogType.LetterInsert : DataLogType.LetterUpdate), requester); if (!string.IsNullOrEmpty(logResult)) { ResultDetail logException = new ResultDetail(); logException.Title = "خطای ثبت لاگ"; logException.Description = "خطای لاگ برای ثبت نامه"; logException.TechnicalDescription = logResult; result.Details.Add(logException); } } } if (result.Result == false) { result.Message = "عملیات ثبت با خطا همراه بود"; return(result); } else { bool afterSaveException = false; if (letterSetting != null) { if (letterSetting.AfterLetterSaveCodeID != 0) { var resultFunction = codeFunctionHandler.GetCodeFunctionResult(requester, letterSetting.AfterLetterSaveCodeID, message); if (resultFunction.Exception != null) { afterSaveException = true; var logResult = bizLogManager.AddLog(GetAfterUpdateExceptionLog(message, resultFunction.Exception, isNew ? DataLogType.LetterInsert : DataLogType.LetterUpdate), requester); if (!string.IsNullOrEmpty(logResult)) { ResultDetail logException = new ResultDetail(); logException.Title = "خطای ثبت لاگ"; logException.Description = "خطای لاگ برای اقدام بعد از ثبت نامه"; logException.TechnicalDescription = logResult; result.Details.Add(logException); } return(result); } } } if (afterSaveException) { result.Message = "عملیات ثبت با موفقیت انجام شد اما اقدامات بعد از ثبت با خطا همراه بود"; } else { result.Message = "عملیات ثبت با موفقیت انجام شد"; } return(result); } }
public ArchiveResult CreateArchiveItems(ArchiveItemDTO message, DR_Requester requester) { ArchiveResult result = new ArchiveResult(); try { // افزوده شدن نامه ها به آرشیو بعدا بررسی شود if (message.ID != 0) { throw new Exception(); } BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, message.DatItem.TargetEntityID, new List <SecurityAction>() { SecurityAction.ArchiveEdit })) { throw new Exception("عدم دسترسی ثبت آرشیو"); } using (var context = new MyIdeaDataDBEntities()) { var dbArchiveItem = new ArchiveItem(); if (message.DatItem.DataItemID == 0) { dbArchiveItem.MyDataItemID = bizDataItem.GetOrCreateDataItem(message.DatItem); message.DatItem.DataItemID = dbArchiveItem.MyDataItemID; } else { dbArchiveItem.MyDataItemID = message.DatItem.DataItemID; } //var dataItem = bizDataItem.GetOrCreateDataItem(message.DatItem); //var archiveItemDataItem = new MyDataItem_ArchiveItem(); dbArchiveItem.FolderID = message.FolderID; dbArchiveItem.CreationDate = DateTime.Now; dbArchiveItem.UserID = requester.Identity; dbArchiveItem.Name = message.Name; var type = GetArchiveItemType(message); message.FileType = type.Item2; message.MainType = type.Item1; dbArchiveItem.FileType = (short)message.FileType; dbArchiveItem.MainType = (short)message.MainType; if (message.AttechedFile != null && message.AttechedFile.Content != null) { dbArchiveItem.FileSize = message.AttechedFile.Content.Count(); dbArchiveItem.FileRepository1 = bizFileRepository.ToFileRepository(context, message.AttechedFile); } SetPossibleThumbnail(context, dbArchiveItem, message.MainType, message.FileType, message.AttechedFile.Content, message.AttechedFile.FileName); //if (!hasThumbnail) //{ // dbArchiveItem.ThumbnailFileRepositoryID = null; // // dbArchiveItem.FileRepository1 = null; //} foreach (var tagid in message.TagIDs) { dbArchiveItem.ArchiveItem_Tag.Add(new ArchiveItem_Tag() { TagID = tagid }); } context.ArchiveItem.Add(dbArchiveItem); context.SaveChanges(); message.ID = dbArchiveItem.ID; result.Result = true; //انتیتی فرمورک قاطی داره رابطه فایل را برای تامبنیل هم میزاره //context.SaveChanges(); } } catch (Exception ex) { result.Result = false; result.Message = ex.Message; } finally { var logResult = bizLogManager.AddLog(GetCreateItemDataLog(message, result.Message), requester); if (!string.IsNullOrEmpty(logResult)) { result.Message += (!string.IsNullOrEmpty(result.Message) ? Environment.NewLine : "") + "خطا در ثبت لاگ" + " , " + logResult; } } return(result); }
public ArchiveDeleteResult DeleteArchiveItemDataItems(List <int> items, DR_Requester requester) { ArchiveDeleteResult result = new ArchiveDeleteResult(); using (var context = new MyIdeaDataDBEntities()) { bool saved = false; bool exceptioned = false; foreach (var item in items) { string exception = ""; //itemResult.ID = item.ID; var dbItem = context.ArchiveItem.First(x => x.ID == item); try { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, dbItem.MyDataItem.TableDrivedEntityID, new List <SecurityAction>() { SecurityAction.ArchiveEdit })) { throw new Exception("عدم دسترسی ثبت نامه"); } while (dbItem.ArchiveItem_Tag.Any()) { context.ArchiveItem_Tag.Remove(dbItem.ArchiveItem_Tag.First()); } context.ArchiveItem.Remove(dbItem); //سکوریتی حذف میتونه اینجا هم چک بشه context.SaveChanges(); saved = true; //itemResult.Result = true; } catch (Exception ex) { exception = ex.Message; ResultDetail itemResult = new ResultDetail(); exceptioned = true; itemResult.Title = "خطا"; itemResult.Description = "حذف فایل با شناسه" + " " + dbItem.ID + " " + "با خطا همراه بود"; itemResult.TechnicalDescription = ex.Message; result.Details.Add(itemResult); } finally { var logResult = bizLogManager.AddLog(GetDeleteItemDataLog(dbItem, exception), requester); if (!string.IsNullOrEmpty(logResult)) { ResultDetail logException = new ResultDetail(); logException.Title = "خطای ثبت لاگ"; logException.Description = "ثبت لاگ برای حذف فایل با شناسه" + " " + dbItem.ID + " " + "با خطا همراه بود"; logException.TechnicalDescription = logResult; result.Details.Add(logException); } } } if (saved && exceptioned) { result.Message = "حذف برخی از فایلها با خطا همراه بود"; } else if (saved) { result.Message = "عملیات حذف با موفقیت انجام شد"; } else if (exceptioned) { result.Message = "عملیات حذف با خطا همراه بود"; } else { result.Message = "عملیات حذف انجام نشد"; } } return(result); }