public long UpdateImportRequirement(ImportRequirementObject importClassificationRequirement, List <ImportRequirementObject> importClassificationRequirements) { try { return(_importClassificationRequirementManager.UpdateImportRequirement(importClassificationRequirement, importClassificationRequirements)); } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateImportRequirement(ImportRequirementObject importReq, List <ImportRequirementObject> newReqs) { try { if (importReq == null || !newReqs.Any()) { return(-2); } using (var db = new ImportPermitEntities()) { var oldReqs = db.ImportRequirements.Where(r => r.ImportStageId == importReq.ImportStageId && r.ImportStageId == importReq.ImportStageId).ToList(); if (!oldReqs.Any()) { return(-2); } var newRequirements = new List <ImportRequirementObject>(); if (newReqs != null) { newRequirements = newReqs; } if (newRequirements.Any()) { if (oldReqs.Any()) { var oldMatch = oldReqs[0]; var newMatch = newRequirements[0]; if (oldMatch.ImportStageId != newMatch.ImportStageId || oldMatch.ImportStageId != newMatch.ImportStageId) { oldReqs.ForEach(k => { db.ImportRequirements.Remove(k); db.SaveChanges(); oldReqs.Remove(k); }); } } newRequirements.ForEach(k => { if (!oldReqs.Exists(n => n.DocumentTypeId == k.DocumentTypeId)) { if (db.ImportRequirements.Count(m => m.ImportStageId == importReq.Id && m.DocumentTypeId == k.DocumentTypeId) < 1) { var importReqReqEntity = ModelMapper.Map <ImportRequirementObject, ImportRequirement>(k); if (importReqReqEntity != null && importReqReqEntity.DocumentTypeId > 0 && importReqReqEntity.Id > 0) { db.ImportRequirements.Add(importReqReqEntity); db.SaveChanges(); } } } }); if (oldReqs.Any()) { oldReqs.ForEach(c => { if (!newRequirements.Exists(n => n.DocumentTypeId == c.DocumentTypeId)) { db.ImportRequirements.Remove(c); db.SaveChanges(); } }); } } return(importReq.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }