async private void accountSelected(object o)
        {
            if (o is Claim)
            {
                Claim = o as Claim;
                // Retrieve the Customer, Property Address, Billing Address, previous Inspection, and Lead information.
                Customer           = Customers.Where(c => c.CustomerID == Claim.CustomerID).Single();
                IsExistingCustomer = true;

                PropertyAddress   = Addresses.Where(a => a.AddressID == Claim.PropertyID).Single();
                IsExistingAddress = true;

                // Check if the BillingID is the same as PropertyID
                if (Claim.BillingID == Claim.PropertyID)
                {
                    /// BillingSameAsProperty = true;
                    BillingAddress = PropertyAddress;
                }
                else // If it's not retrieve the BillingAddress from the server
                {
                    ///BillingSameAsProperty = false;
                    BillingAddress = Addresses.Where(a => a.AddressID == Claim.BillingID).Single();
                }

                Lead = Leads.Where(l => l.LeadID == Claim.LeadID).Single();

                if (Lead.LeadTypeID == 1)
                {
                    if ((ErrorMessage = await new ServiceLayer().GetKnockerResponseByID(new DTO_KnockerResponse {
                        KnockerResponseID = (int)Lead.KnockerResponseID
                    })) != null)
                    {
                        return;
                    }
                    else
                    {
                        KnockerResponse = new KnockerResponse(ServiceLayer.KnockerResponse);
                    }
                }
                else if (Lead.LeadTypeID == 2)
                {
                    if ((ErrorMessage = await new ServiceLayer().GetReferrerByID(new DTO_Referrer {
                        ReferrerID = (int)Lead.CreditToID
                    })) != null)
                    {
                        return;
                    }
                    else
                    {
                        Referrer = new Referrer(ServiceLayer.Referrer);
                    }
                }

                Inspection = Inspections.Where(i => i.ClaimID == Claim.ClaimID).Single();

                Claim.InsuranceCompanyName = InsuranceCompanies.Where(i => i.InsuranceCompanyID == Claim.InsuranceCompanyID).Single().CompanyName;
            }
            else if (o is Lead)
            {
                Lead = o as Lead;
                // Retrieve the Customer and Property Address Information, and Claim if there is one attached.
                Customer           = Customers.Where(c => c.CustomerID == Lead.CustomerID).Single();
                IsExistingCustomer = true;
                PropertyAddress    = Addresses.Where(a => a.AddressID == Lead.AddressID).Single();
                IsExistingAddress  = true;
                BillingAddress     = null;

                // Check if any Claims are connected to the Lead
                if (Claims.Any(c => c.LeadID == Lead.LeadID))
                {
                    Claim = Claims.Where(c => c.LeadID == Lead.LeadID).Single();

                    // Check if BillingID is the same as PropertyID
                    if (Claim.BillingID == Claim.PropertyID)
                    {
                        ///BillingSameAsProperty = true;
                        BillingAddress     = PropertyAddress;
                        IsExistingAddressB = true;
                    }
                    else // If it's not retrieve the BillingAddress from the server
                    {
                        ///BillingSameAsProperty = false;
                        BillingAddress = Addresses.Where(a => a.AddressID == Claim.BillingID).Single();
                    }

                    // Retrieve the Inspection attached to the Claim
                    if ((ErrorMessage = await new ServiceLayer().GetInspectionsByClaimID(Claim.toDTO())) != null)
                    {
                        return;
                    }

                    Inspection = new Inspection(ServiceLayer.InspectionsList.Last());
                }
                else // Instantiate the Claim object
                {
                    Claim = new Claim {
                        LeadID = Lead.LeadID
                    };
                }

                BillingAddress = new Address();
                ///LeadIsAttached = true;
            }
            else if (o is Customer)
            {
                Customer = o as Customer;
            }
            else if (o is Address && code == 4)
            {
                PropertyAddress = o as Address;
            }
            else if (o is Address && code == 5)
            {
                BillingAddress = o as Address;
            }

            else if (o is Adjuster && code == 6)
            {
                Adjuster = o as Adjuster;
            }
            else if (o is Adjustment && code == 7)
            {
                Adjustment = o as Adjustment;
            }
            else if (o == null)
            {
                //AddLead.Execute(o);
            }

            CurrentPage = new ClaimHUDView();
            //OnRequestClose(this, new EventArgs());
        }
示例#2
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);


            foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
            {
                relationship.DeleteBehavior = DeleteBehavior.Restrict;
            }

            var internalBuilder = modelBuilder.GetInfrastructure();

            foreach (var entity in modelBuilder.Model.GetEntityTypes())
            {
                internalBuilder
                .Entity(entity.Name, ConfigurationSource.Convention)
                .Relational(ConfigurationSource.Convention)
                .ToTable(entity.ClrType.Name);
            }

            modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);

            modelBuilder.Query <LeadMatrix>().ToQuery(() =>

                                                      Leads.Where(x => x.IsDeleted == false).GroupBy(t => new
            {
                t.MarketerId,
                t.MarketerOrganizationId,
                t.Created.Date,
                t.Status
            }).Select(g => new LeadMatrix()
            {
                MarketerId             = g.Key.MarketerId,
                MarketerOrganizationId = g.Key.MarketerOrganizationId,
                Status = g.Key.Status,
                Date   = g.Key.Date,
                Count  = g.Count()
            }));

            modelBuilder.Query <TimeMatrix>().ToQuery(() =>

                                                      TimeEntries.Where(x => x.IsDeleted == false).GroupBy(t => new
            {
                t.ContractId,
                t.StartDate.Date,
                t.RecruiterId,
                t.RecruitingOrganizationId,
                t.MarketerId,
                t.MarketingOrganizationId,
                t.ContractorId,
                t.ProviderOrganizationId,
                t.AccountManagerId,
                t.ProjectManagerId,
                t.CustomerId,
                t.CustomerOrganizationId,
                t.ProjectId,
                t.StoryId,
                t.Status,
                t.TimeType,
                t.TotalAccountManagerStream,
                t.TotalAgencyStream,
                t.TotalRecruitingAgencyStream,
                t.TotalMarketingAgencyStream,
                t.TotalContractorStream,
                t.TotalCustomerAmount,
                t.TotalMarketerStream,
                t.TotalProjectManagerStream,
                t.TotalRecruiterStream,
                t.TotalSystemStream
            }).Select(g => new TimeMatrix()
            {
                ProjectId  = g.Key.ProjectId,
                StoryId    = g.Key.StoryId,
                TimeType   = g.Key.TimeType,
                TimeStatus = g.Key.Status,
                TotalAccountManagerStream   = g.Key.TotalAccountManagerStream,
                TotalAgencyStream           = g.Key.TotalAgencyStream,
                TotalMarketingAgencyStream  = g.Key.TotalMarketingAgencyStream,
                TotalRecruitingAgencyStream = g.Key.TotalRecruitingAgencyStream,
                TotalContractorStream       = g.Key.TotalContractorStream,
                TotalCustomerAmount         = g.Key.TotalCustomerAmount,
                TotalMarketerStream         = g.Key.TotalMarketerStream,
                TotalProjectManagerStream   = g.Key.TotalProjectManagerStream,
                TotalRecruiterStream        = g.Key.TotalRecruiterStream,
                TotalSystemStream           = g.Key.TotalSystemStream,

                RecruiterId = g.Key.RecruiterId,

                RecruiterOrganizationId = g.Key.RecruitingOrganizationId,
                MarketerId             = g.Key.MarketerId,
                MarketerOrganizationId = g.Key.MarketingOrganizationId,
                ContractorId           = g.Key.ContractorId,
                ProviderOrganizationId = g.Key.ProviderOrganizationId,
                AccountManagerId       = g.Key.AccountManagerId,
                ProjectManagerId       = g.Key.ProjectManagerId,
                CustomerId             = g.Key.CustomerId,
                CustomerOrganizationId = g.Key.CustomerOrganizationId,
                Date       = g.Key.Date,
                ContractId = g.Key.ContractId,
                Hours      = g.Sum(e => e.TotalHours)
            })
                                                      );
            modelBuilder.Query <TimeMatrix>().HasOne(x => x.Contract).WithOne()
            .HasForeignKey <TimeMatrix>(x => x.ContractId);

            modelBuilder.Entity <Notification>()
            .ToTable("Notification")
            .HasDiscriminator(x => x.Type)
            .HasValue <LeadNotification>(NotificationType.Lead)
            .HasValue <CandidateNotification>(NotificationType.Candidate)
            .HasValue <PersonNotification>(NotificationType.Person)
            .HasValue <WorkOrderNotification>(NotificationType.WorkOrder)
            .HasValue <ContractNotification>(NotificationType.Contract)
            .HasValue <ProjectNotification>(NotificationType.Project)
            .HasValue <ProposalNotification>(NotificationType.Proposal)
            .HasValue <StoryNotification>(NotificationType.Story)
            .HasValue <TimeEntryNotification>(NotificationType.TimeEntry)
            .HasValue <UserNotification>(NotificationType.User)
            .HasValue <SystemNotification>(NotificationType.System);

            modelBuilder.Entity <Notification>()
            .Property(e => e.Id)
            .ValueGeneratedOnAdd();

            modelBuilder.Entity <Notification>()
            .Property(p => p.Message)
            .HasMaxLength(200);

            modelBuilder.Entity <Notification>()
            .Property <DateTimeOffset>("Created")
            .HasDefaultValueSql("SYSDATETIMEOFFSET()");

            modelBuilder.Entity <Notification>()
            .Property <DateTimeOffset>("Updated")
            .HasDefaultValueSql("SYSDATETIMEOFFSET()");


            //modelBuilder.Query<TimeMatrix>().HasOne(x => x.Project).WithOne();

            //modelBuilder.Query<TimeMatrix>().HasOne(x => x.OrganizationContractor).WithOne();
            //modelBuilder.Query<TimeMatrix>().HasOne(x => x.OrganizationAccountManager).WithOne();
            //modelBuilder.Query<TimeMatrix>().HasOne(x => x.OrganizationCustomer).WithOne();
            //modelBuilder.Query<TimeMatrix>().HasOne(x => x.OrganizationRecruiter).WithOne();
            //modelBuilder.Query<TimeMatrix>().HasOne(x => x.OrganizationMarketer).WithOne();
            //modelBuilder.Query<TimeMatrix>().HasOne(x => x.OrganizationProjectManager).WithOne();
        }