public void GetTest_Excpetion_CustomerExistButIsDelete()
        {
            Customer customer = CreateCustomer("CustomerDescriptionDontExist");
            int      id       = customer.CustomerId;

            CustomerDescription customerDescriptionExpected = new CustomerDescription
            {
                Customer  = customer,
                Pregnancy = new Pregnancy {
                    ChildBirthExpectedDate = DateTime.Now + new TimeSpan(150, 0, 0, 0)
                },
                PersonnalFollowUp = null,
                LegalCustody      = _context.LegalCustodies.Find(1),
                ChildrenCount     = 3,
                Sex                             = _context.Sexs.Find(1),
                Parent                          = _context.Parents.Find(1),
                MaritalStatus                   = null,
                CitizenStatus                   = _context.CitizenStatuses.Find(2),
                FamilyType                      = _context.FamilyTypes.Find(1),
                LanguageSpoken                  = _context.Languages.Find(1),
                HomeType                        = _context.HomeTypes.Find(4),
                TransportType                   = null,
                Schooling                       = _context.Schoolings.Find(2),
                IncomeSource                    = _context.IncomeSources.Find(1),
                Availability                    = _context.Availabilities.Find(3),
                YearlyIncome                    = _context.YearlyIncomes.Find(2),
                WantsToBecomeMember             = null,
                HasMentalHealthDiagnostic       = false,
                HasBeenHospitalisedInPsychiatry = true,
                HasContactWithDPJinPast         = true,
                HasContactWithDPJnow            = false,
                WillParticipateToHelpingGroup   = true,
            };

            var activation = customer.CustomerActivations.Where(ca => ca.IsActive == true).SingleOrDefault();

            activation.IsActive = false;
            _context.Update(customer);
            _context.SaveChanges();

            var response = _mediator.Send(new GetCustomerDescriptionQuery {
                CustomerDescriptionId = id
            }).ShouldThrow(typeof(EntityNotFoundException));
        }
Пример #2
0
 public Sale(CustomerDescription cd)
 {
     id = cd.GetKundeNr();
 }
        public async Task <GetCustomerDescriptionModel> Handle(GetCustomerDescriptionQuery request, CancellationToken cancellationToken)
        {
            Customer customer = await _context.Customers
                                .Include(c => c.CustomerActivations)
                                .Where(c => c.CustomerId == request.CustomerDescriptionId).SingleOrDefaultAsync() ?? throw new EntityNotFoundException(nameof(Customer));

            if (!customer.CustomerActivations.Where(ca => ca.IsActive == true).Any())
            {
                throw new EntityNotFoundException(nameof(Customer));
            }

            CustomerDescription customerDescription = _context.CustomerDescriptions
                                                      .Include(cd => cd.Pregnancy)
                                                      .Include(cd => cd.PersonnalFollowUp)
                                                      .Include(cd => cd.Sex)
                                                      .Include(cd => cd.Parent)
                                                      .Include(cd => cd.MaritalStatus)
                                                      .Include(cd => cd.CitizenStatus)
                                                      .Include(cd => cd.FamilyType)
                                                      .Include(cd => cd.LanguageSpoken)
                                                      .Include(cd => cd.HomeType)
                                                      .Include(cd => cd.TransportType)
                                                      .Include(cd => cd.Schooling)
                                                      .Include(cd => cd.IncomeSource)
                                                      .Include(cd => cd.Availability)
                                                      .Include(cd => cd.YearlyIncome)
                                                      .Include(cd => cd.LegalCustody)
                                                      .Include(cd => cd.PreferedDays)
                                                      .Include(cd => cd.CustomerChildrenAgeBracket)
                                                      .ThenInclude(x => x.AgeBracket)
                                                      .Include(cd => cd.CustomerSkillToDevelop)
                                                      .ThenInclude(x => x.Skill)
                                                      .Include(cd => cd.CustomerSocialService)
                                                      .ThenInclude(x => x.SocialService)
                                                      .Where(cd => cd.CustomerDescriptionId == request.CustomerDescriptionId)
                                                      .SingleOrDefault();

            if (customerDescription == null)
            {
                throw new EntityNotFoundException(nameof(CustomerDescription));
            }

            var model = new GetCustomerDescriptionModel
            {
                CustomerDescriptionId         = request.CustomerDescriptionId,
                FileNumber                    = customer.FileNumber,
                IsPregnant                    = customerDescription.Pregnancy != null ? true : false,
                PregnancyExpectedDate         = customerDescription.Pregnancy?.ChildBirthExpectedDate,
                HasPersonnalFollowUp          = customerDescription.PersonnalFollowUp != null ? true : false,
                PersonnalFollowUpMeetingCount = customerDescription.PersonnalFollowUp?.MeetingCount,
                ChildrenCount                 = customerDescription.ChildrenCount,
                SexId               = customerDescription.SexId,
                Sex                 = customerDescription.Sex?.Name,
                ParentId            = customerDescription.ParentId,
                Parent              = customerDescription.Parent?.Name,
                MaritalStatusId     = customerDescription.MaritalStatusId,
                MaritalStatus       = customerDescription.MaritalStatus?.Name,
                CitizenStatusId     = customerDescription.CitizenStatusId,
                CitizenStatus       = customerDescription.CitizenStatus?.Name,
                FamilyTypeId        = customerDescription.FamilyTypeId,
                FamilyType          = customerDescription.FamilyType?.Name,
                LanguageSpokenId    = customerDescription.LanguageSpokenId,
                LanguageSpoken      = customerDescription.LanguageSpoken?.Name,
                HomeTypeId          = customerDescription.HomeTypeId,
                HomeType            = customerDescription.HomeType?.Name,
                TransportTypeId     = customerDescription.TransportTypeId,
                TransportType       = customerDescription.TransportType?.Name,
                SchoolingId         = customerDescription.SchoolingId,
                Schooling           = customerDescription.Schooling?.Name,
                IncomeSourceId      = customerDescription.IncomeSourceId,
                IncomeSource        = customerDescription.IncomeSource?.Name,
                AvailabilityId      = customerDescription.AvailabilityId,
                Availability        = customerDescription.Availability?.Name,
                YearlyIncomeId      = customerDescription.YearlyIncomeId,
                YearlyIncomeName    = customerDescription.YearlyIncome?.Name,
                LegalCustodyId      = customerDescription.LegalCustodyId,
                LegalCustody        = customerDescription.LegalCustody?.Name,
                WantsToBecomeMember = customerDescription.WantsToBecomeMember,

                HasMentalHealthDiagnostic       = customerDescription.HasMentalHealthDiagnostic,
                HasBeenHospitalisedInPsychiatry = customerDescription.HasBeenHospitalisedInPsychiatry,
                HasContactWithDPJnow            = customerDescription.HasContactWithDPJnow,
                WillParticipateToHelpingGroup   = customerDescription.WillParticipateToHelpingGroup,
                HasContactWithDPJinPast         = customerDescription.HasContactWithDPJinPast
            };

            foreach (var day in customerDescription.PreferedDays)
            {
                model.PreferedDays.Add(day.Day);
            }
            foreach (var customerAgeBracket in customerDescription.CustomerChildrenAgeBracket)
            {
                model.CustomerChildrenAgeBracket.Add(customerAgeBracket.AgeBracket.Name);
            }
            foreach (var customerSkill in customerDescription.CustomerSkillToDevelop)
            {
                model.CustomerSkillToDevelop.Add(customerSkill.Skill.Name);
            }
            foreach (var customerSocialService in customerDescription.CustomerSocialService)
            {
                model.CustomerSocialService.Add(customerSocialService.SocialService.Name);
            }

            return(model);
        }
        public void GetTest_Success_SomeNull()
        {
            Customer customer      = CreateCustomer("SomeNull");
            int      id            = customer.CustomerId;
            DateTime pregnanceDate = DateTime.Now + new TimeSpan(155, 0, 0, 0);

            CustomerDescription customerDescriptionExpected = new CustomerDescription
            {
                Customer  = customer,
                Pregnancy = new Pregnancy {
                    ChildBirthExpectedDate = pregnanceDate
                },
                PersonnalFollowUp = null,
                LegalCustody      = _context.LegalCustodies.Find(1),
                ChildrenCount     = 3,
                Sex                             = _context.Sexs.Find(1),
                Parent                          = _context.Parents.Find(1),
                MaritalStatus                   = null,
                CitizenStatus                   = _context.CitizenStatuses.Find(2),
                FamilyType                      = _context.FamilyTypes.Find(1),
                LanguageSpoken                  = _context.Languages.Find(1),
                HomeType                        = _context.HomeTypes.Find(4),
                TransportType                   = null,
                Schooling                       = _context.Schoolings.Find(2),
                IncomeSource                    = _context.IncomeSources.Find(1),
                Availability                    = _context.Availabilities.Find(3),
                YearlyIncome                    = _context.YearlyIncomes.Find(2),
                WantsToBecomeMember             = null,
                HasMentalHealthDiagnostic       = false,
                HasBeenHospitalisedInPsychiatry = true,
                HasContactWithDPJinPast         = true,
                HasContactWithDPJnow            = false,
                WillParticipateToHelpingGroup   = true,
            };

            customerDescriptionExpected.PreferedDays.Add(new PreferedDay {
                CustomerDescription = customerDescriptionExpected, Day = DayOfWeek.Friday, IsDelete = false
            });
            customerDescriptionExpected.PreferedDays.Add(new PreferedDay {
                CustomerDescription = customerDescriptionExpected, Day = DayOfWeek.Saturday, IsDelete = false
            });

            customerDescriptionExpected.CustomerChildrenAgeBracket.Add(new CustomerChildrenAgeBracket {
                Customer = customerDescriptionExpected, AgeBracketId = 1, IsDelete = false
            });
            customerDescriptionExpected.CustomerChildrenAgeBracket.Add(new CustomerChildrenAgeBracket {
                Customer = customerDescriptionExpected, AgeBracketId = 3, IsDelete = false
            });

            _context.Add(customerDescriptionExpected);
            _context.SaveChanges();

            var response = _mediator.Send(new GetCustomerDescriptionQuery {
                CustomerDescriptionId = id
            }).Result;

            response.ShouldBeOfType(typeof(GetCustomerDescriptionModel));
            response.CustomerDescriptionId.ShouldBe(id);

            response.PregnancyExpectedDate.ShouldBe(pregnanceDate);
            response.PersonnalFollowUpMeetingCount.ShouldBe(null);
            response.LegalCustody.ShouldBe(_context.LegalCustodies.Find(1).Name);
            response.ChildrenCount.ShouldBe(3);
            response.Sex.ShouldBe(_context.Sexs.Find(1).Name);
            response.Parent.ShouldBe(_context.Parents.Find(1).Name);
            response.MaritalStatus.ShouldBe(null);
            response.CitizenStatus.ShouldBe(_context.CitizenStatuses.Find(2).Name);
            response.FamilyType.ShouldBe(_context.FamilyTypes.Find(1).Name);
            response.LanguageSpoken.ShouldBe(_context.Languages.Find(1).Name);
            response.HomeType.ShouldBe(_context.HomeTypes.Find(4).Name);
            response.TransportType.ShouldBe(null);
            response.Schooling.ShouldBe(_context.Schoolings.Find(2).Name);
            response.IncomeSource.ShouldBe(_context.IncomeSources.Find(1).Name);
            response.Availability.ShouldBe(_context.Availabilities.Find(3).Name);
            response.YearlyIncomeName.ShouldBe(_context.YearlyIncomes.Find(2).Name);

            response.WantsToBecomeMember.ShouldBe(null);
            response.HasMentalHealthDiagnostic.ShouldBe(false);
            response.HasBeenHospitalisedInPsychiatry.ShouldBe(true);
            response.HasContactWithDPJinPast.ShouldBe(true);
            response.HasContactWithDPJnow.ShouldBe(false);
            response.WillParticipateToHelpingGroup.ShouldBe(true);

            response.PreferedDays.ShouldBeOfType(typeof(List <DayOfWeek>));
            response.PreferedDays.Count().ShouldBe(2);
            response.PreferedDays.Where(pd => pd.ToString().Equals("Friday")).Any().ShouldBe(true);
            response.PreferedDays.Where(pd => pd.ToString().Equals("Saturday")).Any().ShouldBe(true);

            response.CustomerSkillToDevelop.ShouldBeOfType(typeof(List <string>));
            response.CustomerSkillToDevelop.Count().ShouldBe(0);

            response.CustomerChildrenAgeBracket.ShouldBeOfType(typeof(List <string>));
            response.CustomerChildrenAgeBracket.Count().ShouldBe(2);
            response.CustomerChildrenAgeBracket.Where(ccab => ccab.Equals(_context.ChildrenAgeBrackets.Find(1).Name)).Any().ShouldBe(true);
            response.CustomerChildrenAgeBracket.Where(ccab => ccab.Equals(_context.ChildrenAgeBrackets.Find(3).Name)).Any().ShouldBe(true);

            response.CustomerSocialService.ShouldBeOfType(typeof(List <string>));
            response.CustomerSocialService.Count().ShouldBe(0);
        }
        public void GetTest_Success_AllNullAndEmptyList()
        {
            Customer customer = CreateCustomer("AllNullAndEmptyList");
            int      id       = customer.CustomerId;

            CustomerDescription customerDescriptionExpected = new CustomerDescription
            {
                Customer          = customer,
                Pregnancy         = null,
                PersonnalFollowUp = null,
                LegalCustody      = null,
                ChildrenCount     = 3,
                Sex                             = null,
                Parent                          = null,
                MaritalStatus                   = null,
                CitizenStatus                   = null,
                FamilyType                      = null,
                LanguageSpoken                  = null,
                HomeType                        = null,
                TransportType                   = null,
                Schooling                       = null,
                IncomeSource                    = null,
                Availability                    = null,
                YearlyIncome                    = null,
                WantsToBecomeMember             = null,
                HasMentalHealthDiagnostic       = false,
                HasBeenHospitalisedInPsychiatry = true,
                HasContactWithDPJinPast         = true,
                HasContactWithDPJnow            = false,
                WillParticipateToHelpingGroup   = true,
            };

            _context.Add(customerDescriptionExpected);
            _context.SaveChanges();

            var response = _mediator.Send(new GetCustomerDescriptionQuery {
                CustomerDescriptionId = id
            }).Result;

            response.ShouldBeOfType(typeof(GetCustomerDescriptionModel));
            response.CustomerDescriptionId.ShouldBe(id);

            response.PregnancyExpectedDate.ShouldBe(null);
            response.PersonnalFollowUpMeetingCount.ShouldBe(null);
            response.LegalCustody.ShouldBe(null);
            response.ChildrenCount.ShouldBe(3);
            response.Sex.ShouldBe(null);
            response.Parent.ShouldBe(null);
            response.MaritalStatus.ShouldBe(null);
            response.CitizenStatus.ShouldBe(null);
            response.FamilyType.ShouldBe(null);
            response.LanguageSpoken.ShouldBe(null);
            response.HomeType.ShouldBe(null);
            response.TransportType.ShouldBe(null);
            response.Schooling.ShouldBe(null);
            response.IncomeSource.ShouldBe(null);
            response.Availability.ShouldBe(null);
            response.YearlyIncomeName.ShouldBe(null);

            response.WantsToBecomeMember.ShouldBe(null);
            response.HasMentalHealthDiagnostic.ShouldBe(false);
            response.HasBeenHospitalisedInPsychiatry.ShouldBe(true);
            response.HasContactWithDPJinPast.ShouldBe(true);
            response.HasContactWithDPJnow.ShouldBe(false);
            response.WillParticipateToHelpingGroup.ShouldBe(true);

            response.PreferedDays.ShouldBeOfType(typeof(List <DayOfWeek>));
            response.PreferedDays.Count().ShouldBe(0);

            response.CustomerSkillToDevelop.ShouldBeOfType(typeof(List <string>));
            response.CustomerSkillToDevelop.Count().ShouldBe(0);

            response.CustomerChildrenAgeBracket.ShouldBeOfType(typeof(List <string>));
            response.CustomerChildrenAgeBracket.Count().ShouldBe(0);

            response.CustomerSocialService.ShouldBeOfType(typeof(List <string>));
            response.CustomerSocialService.Count().ShouldBe(0);
        }
        public async Task <Unit> Handle(UpdateCustomerDescriptionCommand request, CancellationToken cancellationToken)
        {
            CustomerDescription customerDescription = await _context.CustomerDescriptions
                                                      .Include(cd => cd.Customer)
                                                      .Include(cd => cd.Pregnancy)
                                                      .Include(cd => cd.PersonnalFollowUp)
                                                      .Include(cd => cd.CustomerChildrenAgeBracket)
                                                      .Include(cd => cd.CustomerSkillToDevelop)
                                                      .Include(cd => cd.CustomerSocialService)
                                                      .Include(cd => cd.PreferedDays)
                                                      .SingleOrDefaultAsync(cd => cd.CustomerDescriptionId == request.CustomerDescriptionId);

            if (request.PregnancyExpectedDate != null)
            {
                if (customerDescription.Pregnancy == null)
                {
                    customerDescription.Pregnancy = new Pregnancy {
                        CustomerDescription = customerDescription, ChildBirthExpectedDate = (DateTime)request.PregnancyExpectedDate, IsDelete = false
                    };
                }
                else
                {
                    customerDescription.Pregnancy.ChildBirthExpectedDate = (DateTime)request.PregnancyExpectedDate;
                }
            }
            else
            {
                customerDescription.Pregnancy = null;
            }

            if (request.PersonnalFollowUpMeetingCount != null)
            {
                if (customerDescription.PersonnalFollowUp == null)
                {
                    customerDescription.PersonnalFollowUp = new PersonnalFollowUp {
                        CustomerDescription = customerDescription, MeetingCount = (int)request.PersonnalFollowUpMeetingCount, IsDelete = false
                    };
                }
                else
                {
                    customerDescription.PersonnalFollowUp.MeetingCount = (int)request.PersonnalFollowUpMeetingCount;
                }
            }
            else
            {
                customerDescription.PersonnalFollowUp = null;
            }

            if (request.LegalCustodyId != null)
            {
                customerDescription.LegalCustody = await _context.LegalCustodies.FindAsync(request.LegalCustodyId);
            }
            else
            {
                customerDescription.LegalCustody = null;
            }

            customerDescription.ChildrenCount = request.ChildrenCount;

            customerDescription.Sex = (request.SexId == null) ? null : await _context.Sexs.FindAsync(request.SexId);

            customerDescription.Parent = (request.ParentId == null) ? null : await _context.Parents.FindAsync(request.ParentId);

            customerDescription.MaritalStatus = (request.MaritalStatusId == null) ? null : await _context.MaritalStatuses.FindAsync(request.MaritalStatusId);

            customerDescription.CitizenStatus = (request.CitizenStatusId == null) ? null : await _context.CitizenStatuses.FindAsync(request.CitizenStatusId);

            customerDescription.FamilyType = (request.FamilyTypeId == null) ? null : await _context.FamilyTypes.FindAsync(request.FamilyTypeId);

            customerDescription.LanguageSpoken = (request.LanguageSpokenId == null) ? null : await _context.Languages.FindAsync(request.LanguageSpokenId);

            customerDescription.HomeType = (request.HomeTypeId == null) ? null : await _context.HomeTypes.FindAsync(request.HomeTypeId);

            customerDescription.TransportType = (request.TransportTypeId == null) ? null : await _context.TransportTypes.FindAsync(request.TransportTypeId);

            customerDescription.Schooling = (request.SchoolingId == null) ? null : await _context.Schoolings.FindAsync(request.SchoolingId);

            customerDescription.IncomeSource = (request.IncomeSourceId == null) ? null : await _context.IncomeSources.FindAsync(request.IncomeSourceId);

            customerDescription.Availability = (request.AvailabilityId == null) ? null : await _context.Availabilities.FindAsync(request.AvailabilityId);

            customerDescription.YearlyIncome = (request.YearlyIncomeId == null) ? null : await _context.YearlyIncomes.FindAsync(request.YearlyIncomeId);

            customerDescription.WantsToBecomeMember             = (request.WantsToBecomeMember == null) ? null : request.WantsToBecomeMember;
            customerDescription.HasMentalHealthDiagnostic       = request.HasMentalHealthDiagnostic;
            customerDescription.HasBeenHospitalisedInPsychiatry = request.HasBeenHospitalisedInPsychiatry;
            customerDescription.HasContactWithDPJinPast         = request.HasContactWithDPJinPast;
            customerDescription.HasContactWithDPJnow            = request.HasContactWithDPJnow;
            customerDescription.WillParticipateToHelpingGroup   = request.WillParticipateToHelpingGroup;

            customerDescription.PreferedDays.Clear();
            if (request.PreferedDays != null)
            {
                foreach (var day in request.PreferedDays)
                {
                    customerDescription.PreferedDays.Add(new PreferedDay {
                        CustomerDescription = customerDescription, Day = day, IsDelete = false
                    });
                }
            }

            customerDescription.CustomerSkillToDevelop.Clear();
            if (request.CustomerSkillToDevelop != null)
            {
                foreach (var skillId in request.CustomerSkillToDevelop)
                {
                    SkillToDevelop skillToDevelop = await _context.SkillToDevelops.FindAsync(skillId);

                    customerDescription.CustomerSkillToDevelop.Add(new CustomerSkillToDevelop {
                        Customer = customerDescription, Skill = skillToDevelop, IsDelete = false
                    });
                }
            }

            customerDescription.CustomerChildrenAgeBracket.Clear();
            if (request.CustomerChildrenAgeBracket != null)
            {
                foreach (var childrenAgeBracketId in request.CustomerChildrenAgeBracket)
                {
                    ChildrenAgeBracket childrenAgeBracket = await _context.ChildrenAgeBrackets.FindAsync(childrenAgeBracketId);

                    customerDescription.CustomerChildrenAgeBracket.Add(new CustomerChildrenAgeBracket {
                        Customer = customerDescription, AgeBracket = childrenAgeBracket, IsDelete = false
                    });
                }
            }

            customerDescription.CustomerSocialService.Clear();
            if (request.CustomerSocialService != null)
            {
                foreach (var socialServicesId in request.CustomerSocialService)
                {
                    SocialService socialService = await _context.SocialServices.FindAsync(socialServicesId);

                    customerDescription.CustomerSocialService.Add(new CustomerSocialService {
                        Customer = customerDescription, SocialService = socialService, IsDelete = false
                    });
                }
            }

            _context.CustomerDescriptions.Update(customerDescription);
            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }