예제 #1
0
        public async Task <TypedResult <LeadOutDto> > UpdateLead(Guid recordId, NewLeadDtoIn newLeadDtoIn)
        {
            try
            {
                var foundLead = (await LeadCollection.FindAsync(l => l.RecordId == recordId)).FirstOrDefault();
                if (foundLead == null)
                {
                    return(new NotFoundTypedResult <LeadOutDto>());
                }

                foundLead.Address = new AddressEntity
                {
                    StreetLineOne = newLeadDtoIn.Address.StreetLineOne,
                    StreetLineTwo = newLeadDtoIn.Address.StreetLineTwo,
                    AptSuite      = newLeadDtoIn.Address.AptSuite,
                    City          = newLeadDtoIn.Address.City,
                    State         = newLeadDtoIn.Address.State,
                    County        = newLeadDtoIn.Address.County,
                    Zip           = newLeadDtoIn.Address.Zip
                };
                foundLead.Name = new NameEntity
                {
                    FirstName          = newLeadDtoIn.Name.FirstName,
                    LastName           = newLeadDtoIn.Name.LastName,
                    MiddleName         = newLeadDtoIn.Name.MiddleName,
                    Salutation         = newLeadDtoIn.Name.Salutation,
                    PreferredFirstName = newLeadDtoIn.Name.PreferredFirstName
                };
                foundLead.ModifiedBy       = newLeadDtoIn.ModifiedBy;
                foundLead.LastModifiedTime = DateTimeOffset.UtcNow;
                foundLead.AnnualSalary     = newLeadDtoIn.AnnualSalary;
                foundLead.LeadSource       = newLeadDtoIn.LeadSource;
                foundLead.Tags             = newLeadDtoIn.Tags.Select(x => x);
                foundLead.ContactInfo      = new ContactInfoEntity
                {
                    Mobile = newLeadDtoIn.ContactInfo.Mobile,
                    Fax    = newLeadDtoIn.ContactInfo.Fax,
                    Email  = newLeadDtoIn.ContactInfo.Email,
                    Home   = newLeadDtoIn.ContactInfo.Home,
                    PreferredContactMethod = newLeadDtoIn.ContactInfo.PreferredContactMethod
                };

                var updatedLead =
                    await LeadCollection.ReplaceOneAsync(l => l.RecordId == recordId, foundLead, new ReplaceOptions()
                {
                    IsUpsert = false
                });

                return(new SuccessfulTypedResult <LeadOutDto>(LeadOutDto.EntityToOutDto(foundLead)));
            }
            catch (Exception e)
            {
                return(new FailedTypedResult <LeadOutDto>(e));
            }
        }
예제 #2
0
        public async Task <TypedResult <LeadOutDto> > CreateLead(NewLeadDtoIn newLeadDtoIn)
        {
            try
            {
                var dateTimeNow   = DateTimeOffset.UtcNow;
                var newLeadEntity = new LeadEntity
                {
                    RecordId         = Guid.NewGuid(),
                    CreatedTime      = dateTimeNow,
                    CreatedByUserId  = newLeadDtoIn.ModifiedBy,
                    ModifiedBy       = newLeadDtoIn.ModifiedBy,
                    LastModifiedTime = dateTimeNow,
                    AnnualSalary     = newLeadDtoIn.AnnualSalary,
                    LeadSource       = newLeadDtoIn.LeadSource,
                    Tags             = newLeadDtoIn.Tags.Select(x => x),
                    Converted        = false,
                    Address          = new AddressEntity
                    {
                        StreetLineOne = newLeadDtoIn.Address.StreetLineOne,
                        StreetLineTwo = newLeadDtoIn.Address.StreetLineTwo,
                        AptSuite      = newLeadDtoIn.Address.AptSuite,
                        City          = newLeadDtoIn.Address.City,
                        State         = newLeadDtoIn.Address.State,
                        County        = newLeadDtoIn.Address.County,
                        Zip           = newLeadDtoIn.Address.Zip
                    },
                    Name = new NameEntity
                    {
                        FirstName          = newLeadDtoIn.Name.FirstName,
                        LastName           = newLeadDtoIn.Name.LastName,
                        MiddleName         = newLeadDtoIn.Name.MiddleName,
                        Salutation         = newLeadDtoIn.Name.Salutation,
                        PreferredFirstName = newLeadDtoIn.Name.PreferredFirstName
                    },
                    ContactInfo = new ContactInfoEntity
                    {
                        Mobile = newLeadDtoIn.ContactInfo.Mobile,
                        Fax    = newLeadDtoIn.ContactInfo.Fax,
                        Email  = newLeadDtoIn.ContactInfo.Email,
                        Home   = newLeadDtoIn.ContactInfo.Home,
                        PreferredContactMethod = newLeadDtoIn.ContactInfo.PreferredContactMethod
                    }
                };

                await LeadCollection.InsertOneAsync(newLeadEntity);

                return(new SuccessfulTypedResult <LeadOutDto>(LeadOutDto.EntityToOutDto(newLeadEntity)));
            }
            catch (Exception e)
            {
                return(new FailedTypedResult <LeadOutDto>(e));
            }
        }