Exemplo n.º 1
0
        private async Task <bool> AddEntity(RegisterViewModel model,
                                            ICollection <MemberMapping> MemberMappings,
                                            IQueryable <Member> parentEntityList)
        {
            bool isSaveSuccess = true;
            List <MemberMapping> MemberMappingList = new List <MemberMapping>();

            foreach (var record in model.MemberIds)
            {
                var currentParentEntity = parentEntityList.Any(a => a.Id == record);
                if (currentParentEntity)
                {
                    MemberMapping referralEntity = new MemberMapping();
                    MemberMappingList.Add(referralEntity.ToEntity(record, model.Id, model.SessionUserId));
                }
            }

            if (MemberMappingList.Count > 0)
            {
                await _context.MemberMapping.AddRangeAsync(MemberMappingList);

                await _context.SaveChangesAsync();

                isSaveSuccess = true;
            }

            return(isSaveSuccess);
        }
Exemplo n.º 2
0
        private async Task <bool> AddMemberMappingWherePreviousExists(RegisterViewModel model,
                                                                      ICollection <MemberMapping> MemberMappings,
                                                                      IQueryable <Member> members)
        {
            bool isSaveSuccess = true;
            List <MemberMapping> assignedMemberMappings = new List <MemberMapping>();

            foreach (var recordId in model.MemberIds)
            {
                var currentRolePermission = members.Where(a => a.Id == recordId).FirstOrDefault();
                if (currentRolePermission != null)
                {
                    if (!MemberMappings.Any(a => a.RelationMemberId == recordId))
                    {
                        var MemberMappingRepo = new MemberMapping();
                        assignedMemberMappings.Add(MemberMappingRepo.ToEntity(recordId, model.Id, model.SessionUserId));
                    }
                }
            }

            if (assignedMemberMappings.Count > 0)
            {
                await _context.MemberMapping.AddRangeAsync(assignedMemberMappings);

                await _context.SaveChangesAsync();

                isSaveSuccess = true;
            }

            return(isSaveSuccess);
        }