コード例 #1
0
        public int UpdateApprovalForFA(List <FAapproval> ApprovalList)
        {
            try
            {
                int faId = ApprovalList.ElementAt(0).FAid.Value;
                List <FAapproval> ExistingApprovalList = db.FAapprovals.Select(x => x).Where(x => x.FAid.Value == faId).ToList();

                List <FAapproval> ApprovalListToAdd    = new List <FAapproval>();
                List <FAapproval> ApprovalListToUpdate = new List <FAapproval>();
                List <FAapproval> ApprovalListToDelete = new List <FAapproval>();

                foreach (var approval in ApprovalList)
                {
                    FAapproval newApproval = ExistingApprovalList.Select(x => x).Where(x => x.Id == approval.Id).FirstOrDefault();
                    if (newApproval == null)
                    {
                        ApprovalListToAdd.Add(approval);
                    }
                    else
                    {
                        ApprovalListToUpdate.Add(approval);
                    }
                }
                foreach (var approval in ExistingApprovalList)
                {
                    FAapproval existingApproval = ApprovalList.Select(x => x).Where(x => x.Id == approval.Id).FirstOrDefault();
                    if (existingApproval == null)
                    {
                        ApprovalListToDelete.Add(approval);
                    }
                }

                foreach (var approval in ApprovalListToAdd)
                {
                    InsertFAapproval(approval);
                }
                foreach (var approval in ApprovalListToDelete)
                {
                    //RemoveApprovalDetailForFA(approval.Id);
                    FAapproval apprvl = db.FAapprovals.Select(x => x).Where(x => x.Id == approval.Id).FirstOrDefault();
                    db.FAapprovals.Remove(apprvl);
                }
                FAapproval approvalToUpdate;
                foreach (var approval in ApprovalListToUpdate)
                {
                    approvalToUpdate = ExistingApprovalList.Select(x => x).Where(x => x.Id == approval.Id).FirstOrDefault();
                    if (approvalToUpdate != null)
                    {
                        approvalToUpdate.FAApprovedId    = approval.FAApprovedId;
                        approvalToUpdate.PocketId        = approval.PocketId;
                        approvalToUpdate.RecommandedBYSM = approval.RecommandedBYSM;
                    }
                }
                return(db.SaveChanges());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public int PostFAdetailEntities(FAdetailEntities faDetailEntities)
        {
            try
            {
                IFAdetailOperations               faDetailOperations            = new FAdetailOperations();
                IFAaddressDetailOperations        faAddressDetailOperation      = new FAaddressDetailOperations();
                IFAeducationDetailOperations      faEducationDetailOperation    = new FAeducationDetailOperations();
                IFAexperianceDetailOperations     faExperienceDetailOperation   = new FAexperianceDetailOperations();
                IFAtargetOperations               faTargetOperation             = new FAtargetOperations();
                IFAtargetVillageMappingOperations targetVillageMappingOperation = new FAtargetVillageMappingOperations();
                IFAapprovalOperations             faApprovalOperation           = new FAapprovalOperations();

                IFAuploadedDocumentDetailOperations faUploadDocumentDetailOperations = new FAuploadedDocumentDetailOperations();

                FAdetail faDetail = new FAdetail();
                faDetail = MapEntities.Map <FAdetailEntities, FAdetail>(faDetailEntities);
                int faDetailId = faDetailOperations.InsertFAdetail(faDetail);

                FAaddressDetail faAddressDetail = new FAaddressDetail();
                faAddressDetail            = MapEntities.Map <FAaddressDetailEntities, FAaddressDetail>(faDetailEntities.AddressDetailEntities);
                faAddressDetail.FAdetailId = faDetailId;
                int faAddressDetailId = faAddressDetailOperation.InsertFAAddressDetail(faAddressDetail);

                IEnumerable <FAeducationDetail> faEducationDetailList = new List <FAeducationDetail>();
                faEducationDetailList = MapEntities.MapIEnumerableCollection <FAeducationDetailEntities, FAeducationDetail>(faDetailEntities.EducationDetailEntityList);
                faEducationDetailList.ToList().ForEach(x => x.FAid = faDetailId);
                faEducationDetailList = faEducationDetailOperation.InsertFAeducationDetail(faEducationDetailList);

                IEnumerable <FAexperianceDetail> faExperienceDetailList = new List <FAexperianceDetail>();
                faExperienceDetailList = MapEntities.MapIEnumerableCollection <FAexperianceDetailEntities, FAexperianceDetail>(faDetailEntities.ExperienceDetailEntityList);
                faExperienceDetailList.ToList().ForEach(x => x.FAid = faDetailId);
                faExperienceDetailList = faExperienceDetailOperation.InsertFAexperienceDetail(faExperienceDetailList);

                IEnumerable <FAtargetDetail> faTargetDetailList = new List <FAtargetDetail>();
                faTargetDetailList = MapEntities.MapIEnumerableCollection <FAtargetDetailEntities, FAtargetDetail>(faDetailEntities.TargetDetailEntityList);
                faTargetDetailList.ToList().ForEach(x => x.FAid = faDetailId);
                for (int faTargetEntityCount = 0; faTargetEntityCount < faDetailEntities.TargetDetailEntityList.Count(); faTargetEntityCount++)
                {
                    faTargetDetailList.ElementAt(faTargetEntityCount).FAtargetVillageMappings = MapEntities.MapIEnumerableCollection <FAtargetVillageMappingEntities, FAtargetVillageMapping>(faDetailEntities.TargetDetailEntityList.ElementAt(faTargetEntityCount).TargetCropsEntityMappingList).ToList();
                }
                faTargetDetailList = faTargetOperation.InsertTargetsForFA(faTargetDetailList);

                FAapproval faApproval = new FAapproval();
                faApproval      = MapEntities.Map <FAapprovalEntities, FAapproval>(faDetailEntities.ApprovalEntities);
                faApproval.FAid = faDetailId;
                faApproval      = faApprovalOperation.InsertFAapproval(faApproval);

                IEnumerable <FAuploadedDocumentDetail> fauploadDetailList = new List <FAuploadedDocumentDetail>();
                fauploadDetailList = MapEntities.MapIEnumerableCollection <FAuploadedDocumentDetailEntities, FAuploadedDocumentDetail>(faDetailEntities.UploadedDocumentList);
                fauploadDetailList.ToList().ForEach(x => x.FAid = faDetailId);
                fauploadDetailList = faUploadDocumentDetailOperations.InsertUploadedDocumentDetailIst(fauploadDetailList);

                return(faDetailId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
 public FAapproval InsertFAapproval(FAapproval faApproval)
 {
     try
     {
         db.FAapprovals.Add(faApproval);
         db.SaveChanges();
         return(faApproval);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }