async public void submitClaim(object o)
        {
            #region Process Lead

            // Create needed KnockerResponse or Referrer if needed.
            if (Lead.LeadTypeID == 1) // Knocker
            {
                // If KnockerResponse does not exist

                if (KnockerResponse.KnockerResponseID == 0)
                {
                    if ((ErrorMessage = await new ServiceLayer().AddKnockerResponse(KnockerResponse.toDTO())) != null)
                    {
                        return;
                    }
                }
                else
                {
                    if ((ErrorMessage = await new ServiceLayer().UpdateKnockerResponse(KnockerResponse.toDTO())) != null)
                    {
                        return;
                    }
                }

                KnockerResponse        = new KnockerResponse(ServiceLayer.KnockerResponse);
                Lead.KnockerResponseID = KnockerResponse.KnockerResponseID;
                Lead.CreditToID        = KnockerResponse.KnockerID;
                //Lead.CreditTo = Employee.FirstName + " " + Employee.LastName;
            }
            else if (Lead.LeadTypeID == 2) // Referrer
            {
                if (Referrer.ReferrerID == 0)
                {
                    if ((ErrorMessage = await new ServiceLayer().AddReferrer(Referrer.toDTO())) != null)
                    {
                        return;
                    }
                }
                else
                {
                    if ((ErrorMessage = await new ServiceLayer().UpdateReferrer(Referrer.toDTO())) != null)
                    {
                        return;
                    }
                }

                Referrer        = new Referrer(ServiceLayer.Referrer);
                Lead.CreditToID = Referrer.ReferrerID;
                Lead.CreditTo   = Referrer.FirstName + " " + Referrer.LastName;
            }

            Lead.SalespersonID = LoggedInEmployee.EmployeeID;
            Lead.CustomerID    = Customer.CustomerID;
            Lead.AddressID     = PropertyAddress.AddressID;
            Lead.Status        = "A";

            if (Lead.LeadID == 0)
            {
                if ((ErrorMessage = await new ServiceLayer().AddLead(Lead.toDTO())) != null)
                {
                    return;
                }

                Lead.LeadID = ServiceLayer.Lead.LeadID;
            }
            else
            {
                if ((ErrorMessage = await new ServiceLayer().UpdateLead(Lead.toDTO())) != null)
                {
                    return;
                }
            }

            #endregion

            #region Claim
            if (Claim.ClaimID == 0) // If the Claim doesn't exist (it should exist)
            {
                // Create the Claim
                if ((ErrorMessage = await new ServiceLayer().AddClaim(Claim.toDTO())) != null)
                {
                    return;
                }

                // Add it to the Claims list
                Claims.Add(new Claim(ServiceLayer.Claim));
            }
            else if (Claim.ClaimID > 0) // If the Claim does exist (it should)
            {
                // Update the Claim
                if ((ErrorMessage = await new ServiceLayer().UpdateClaim(Claim.toDTO())) != null)
                {
                    return;
                }

                // Overwrite the original Claim in the Claims list with the updated information
                Claim claim = Claims.Where(c => c.ClaimID == Claim.ClaimID).Single();
                int   index = Claims.IndexOf(claim);
                Claims[index] = new Claim(ServiceLayer.Claim);
                Customer      = Customers.Where(c => c.CustomerID == Claim.CustomerID).Single();
                Claims[index].CustomerName = Customer.FirstName + " " + Customer.LastName;
                Claims[index].Address      = Addresses.Where(a => a.AddressID == Claims[index].PropertyID).Single().FullAddress;
            }
            #endregion
        }
Exemplo n.º 2
0
        async private void submitLead(object o)
        {
            #region Process Customer
            if (!IsExistingCustomer)
            {
                if ((ErrorMessage = await new ServiceLayer().AddCustomer(Customer.toDTO())) != null)
                {
                    return;
                }

                Customer = new Customer(ServiceLayer.Customer);
                PropertyAddress.CustomerID = Customer.CustomerID;
            }

            else // If Customer does exist.
            {
                PropertyAddress.CustomerID = Customer.CustomerID;

                if ((ErrorMessage = await new ServiceLayer().UpdateCustomer(Customer.toDTO())) != null)
                {
                    return;
                }
            }
            #endregion

            #region Process Address
            if (PropertyAddress.AddressID == 0)
            {
                if ((ErrorMessage = await new ServiceLayer().AddAddress(PropertyAddress.toDTO())) != null)
                {
                    return;
                }

                PropertyAddress.AddressID = ServiceLayer.Address.AddressID;
            }
            else // If ProeprtyAddress does exist.
            {
                if ((ErrorMessage = await new ServiceLayer().UpdateAddress(PropertyAddress.toDTO())) != null)
                {
                    return;
                }
            }
            #endregion

            #region Process Lead
            if (Lead.LeadTypeID == 1)
            {
                // If KnockerResponse does not exist

                if (KnockerResponse.KnockerResponseID == 0)
                {
                    if ((ErrorMessage = await new ServiceLayer().AddKnockerResponse(KnockerResponse.toDTO())) != null)
                    {
                        return;
                    }

                    KnockerResponse        = new KnockerResponse(ServiceLayer.KnockerResponse);
                    Lead.KnockerResponseID = KnockerResponse.KnockerResponseID;
                    Lead.CreditToID        = KnockerResponse.KnockerID;
                }
                else
                {
                    /// If KnockerRepsonse does exist?
                    /// Perhaps add checkbox to signal create window to select knocker response from table?
                    /// In which case this becomes a KnockerResponseUpdate area.
                }
            }
            else if (Lead.LeadTypeID == 2)
            {
                if (Referrer.ReferrerID == 0)
                {
                    if ((ErrorMessage = await new ServiceLayer().AddReferrer(Referrer.toDTO())) != null)
                    {
                        return;
                    }

                    Referrer        = new Referrer(ServiceLayer.Referrer);
                    Lead.CreditToID = Referrer.ReferrerID;
                }
                else
                {
                    /// If Referrer does exist?
                    /// Perhaps add checkbox to signal create window to select Referrer from table?
                    /// In which case this becomes a ReferrerUpdate area.
                }
            }

            Lead.SalespersonID = LoggedInEmployee.EmployeeID;
            Lead.CustomerID    = Customer.CustomerID;
            Lead.AddressID     = PropertyAddress.AddressID;
            Lead.Status        = "A";

            if (Lead.LeadID == 0)
            {
                if ((ErrorMessage = await new ServiceLayer().AddLead(Lead.toDTO())) != null)
                {
                    return;
                }

                Lead.LeadID = ServiceLayer.Lead.LeadID;
            }
            else
            {
                if ((ErrorMessage = await new ServiceLayer().UpdateLead(Lead.toDTO())) != null)
                {
                    return;
                }
            }

            OnRequestClose(this, new EventArgs());
            #endregion
        }