public FIN_ApproverECLAIMEntity AddApprovers(FIN_ApproverECLAIMEntity model) { var result = new FIN_ApproverECLAIMEntity(); using (var context = new VnrHrmDataContext()) { var status = string.Empty; var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); //lay ds Approved theo profileId var profileId = Common.DotNetToOracle(string.Empty.ToString()); if (model != null && model.ProfileID != null) { profileId = Common.DotNetToOracle(model.ProfileID.ToString()); } if (model != null) { model.ApprovedIDs = model.ApprovedIDs.Where(m => m != Guid.Empty).ToList(); var lstEvaluators = model.ApprovedIDs == null ? new List<Guid>() : model.ApprovedIDs; foreach (var evaluator in lstEvaluators) { result = model.CopyData<FIN_ApproverECLAIMEntity>(); result.ApprovedID = evaluator; Add(result); } if (!lstEvaluators.Any()) { //khi khong chon nguoi danh gia result = model.CopyData<FIN_ApproverECLAIMEntity>(); result.ApprovedID = null; Add(result); } } }//end context return result; }
public FIN_ApproverECLAIMEntity DeleteListApprover(string ID) { var result = new FIN_ApproverECLAIMEntity(); using (var context = new VnrHrmDataContext()) { var status = string.Empty; var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new FIN_ApproverECLAIMRepository(unitOfWork); List<Guid> listID = new List<Guid>(); var list = ID.Split(','); foreach (var x in list) { try { var a = Guid.Parse(x).TryGetValue<Guid>(); if (a != Guid.Empty) listID.Add(a); } catch { } } foreach (var mainID in listID) { var Fin_ApproverClaim = repo.GetById(mainID); var ilFin_Approver = repo.FindBy(x => x.ProfileID == Fin_ApproverClaim.ProfileID && x.ApprovedType == Fin_ApproverClaim.ApprovedType && x.IsDelete == null).ToList(); if (ilFin_Approver == null || ilFin_Approver.Count == 0) { continue; } if (CheckFinApproverHasUse(ilFin_Approver.Select(x => x.ProfileID ?? Guid.Empty).ToList()) == true) { continue; } else { foreach (var item in ilFin_Approver) { item.IsDelete = true; } repo.SaveChanges(); result = ilFin_Approver.FirstOrDefault().CopyData<FIN_ApproverECLAIMEntity>(); } } } return result; }