public async Task <Confirmation> Record(InvolvedPartyCommand command)
        {
            // Load the existing occurrence for which the involved party should be recorded.
            var occurrence = await _occurenceRepo.ReadOccurrenceAsync(command.OccurrenceId);

            if (occurrence == null)
            {
                return(new Confirmation
                {
                    ResultMessage = "Invalid Occurrence"
                });
            }

            InvolvedParty involvedParty = CreateParty(command);

            ValidationResultSet valResultSet = _validation.Validate(involvedParty);

            if (valResultSet.IsInvalid)
            {
                return(new Confirmation
                {
                    Validations = valResultSet.ObjectValidations
                });
            }

            occurrence.AddInvolvedParty(involvedParty);

            // Update the occurrence within the repository.
            await _occurenceRepo.UpdateOccurrenceAsync(occurrence);

            return(new Confirmation
            {
                OccurrenceId = occurrence.OccurrenceId
            });
        }
        // Create contact for party and associate with the involved automobile.
        private static InvolvedParty CreateParty(InvolvedPartyCommand command)
        {
            var contact = Contact.IdentifiedAs(command.FirstName, command.LastName, command.DateOfBirth)
                          .InsuredBy(command.InsuranceCompany, command.PolicyNumber, command.InsuredState)
                          .PrimaryContactInfo(command.PhoneNumber);

            return(InvolvedParty.IdentifiedBy(contact, command.Vin));
        }
        public MaintenanceCompany GetMaintenanceCompanyById(long Id)
        {
            using (var context = new EWUSDbContext())
            {
                MaintenanceCompany maintenanceCompany = new MaintenanceCompany();
                InvolvedParty      ip = context.InvolvedPartys.Where(x => x.Id == Id)
                                        .FirstOrDefault();

                maintenanceCompany = (MaintenanceCompany)ip;

                if (maintenanceCompany != null)
                {
                    return(maintenanceCompany);
                }
                return(null);
            }
        }
        public Result DeleteCustomerById(long Id)
        {
            Result output = new Result();

            output.Status = ResultStatus.BadRequest;

            try
            {
                using (var ctx = new EWUSDbContext())
                {
                    Customer      customer = new Customer();
                    InvolvedParty ip       = ctx.InvolvedPartys.Where(x => x.Id == Id)
                                             .Include(x => x.DocumentItems)
                                             .FirstOrDefault();

                    customer = (Customer)ip;

                    try
                    {
                        ctx.InvolvedPartys.Remove(customer);

                        ctx.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        if (ex.HResult == -2146233087)
                        {
                            output.ExceptionMessage = Constants.ErrorMessageReferentialIntegrity;
                            output.Status           = ResultStatus.Forbidden;
                        }
                        else
                        {
                            output.ExceptionMessage = "Exception could not be performed !!!";
                            output.Status           = ResultStatus.InternalServerError;
                        }
                    }
                }
                output.Status = ResultStatus.OK;
            }
            catch (Exception e)
            {
                output.Status = ResultStatus.InternalServerError;
            }

            return(output);
        }
        public Result DeleteMaintenanceCompanyById(long Id)
        {
            Result output = new Result();

            output.Status = ResultStatus.BadRequest;

            try
            {
                using (var ctx = new EWUSDbContext())
                {
                    MaintenanceCompany maintenanceCompany = new MaintenanceCompany();
                    InvolvedParty      ip = ctx.InvolvedPartys.Where(x => x.Id == Id)
                                            .FirstOrDefault();

                    maintenanceCompany = (MaintenanceCompany)ip;

                    try
                    {
                        ctx.InvolvedPartys.Remove(maintenanceCompany);

                        ctx.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        if (ex.HResult == -2146233087)
                        {
                            output.ExceptionMessage = Constants.ErrorMessageReferentialIntegrity;
                            output.Status           = ResultStatus.Forbidden;
                        }
                        else
                        {
                            output.ExceptionMessage = "Exception could not be performed !!!";
                            output.Status           = ResultStatus.InternalServerError;
                        }
                    }
                }
                output.Status = ResultStatus.OK;
            }
            catch
            {
                output.Status = ResultStatus.InternalServerError;
            }

            return(output);
        }
        public Customer GetCustomerById(long Id)
        {
            using (var context = new EWUSDbContext())
            {
                Customer      customer = new Customer();
                InvolvedParty ip       = context.InvolvedPartys.Where(x => x.Id == Id)
                                         .Include(x => x.DocumentItems)
                                         .FirstOrDefault();

                customer = (Customer)ip;

                if (customer != null)
                {
                    return(customer);
                }
                return(null);
            }
        }