public async Task CreateOrUpdateAsync(PartnerContactModel partnerContact)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var existentPartnerContact = await context.PartnerContacts
                                             .FirstOrDefaultAsync(c => c.LocationId == partnerContact.LocationId);

                if (existentPartnerContact != null)
                {
                    existentPartnerContact = _encryptionService.Decrypt(existentPartnerContact);

                    existentPartnerContact.FirstName   = partnerContact.FirstName;
                    existentPartnerContact.LastName    = partnerContact.LastName;
                    existentPartnerContact.PhoneNumber = partnerContact.PhoneNumber;
                    existentPartnerContact.Email       = partnerContact.Email;

                    existentPartnerContact = _encryptionService.Encrypt(existentPartnerContact);

                    context.PartnerContacts.Update(existentPartnerContact);
                }
                else
                {
                    var entity = PartnerContactEntity.Create(partnerContact);

                    entity = _encryptionService.Encrypt(entity);

                    context.PartnerContacts.Add(entity);
                }

                await context.SaveChangesAsync();
            }
        }
Ejemplo n.º 2
0
        public async Task <PartnerContactErrorCodes> CreateIfNotExistAsync(PartnerContactModel partnerContact)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var existentPartnerContact = await context.PartnerContacts
                                             .FirstOrDefaultAsync(c => c.LocationId == partnerContact.LocationId);

                if (existentPartnerContact != null)
                {
                    return(PartnerContactErrorCodes.PartnerContactAlreadyExists);
                }

                var entity = PartnerContactEntity.Create(partnerContact);

                entity = _encryptionService.Encrypt(entity);

                context.PartnerContacts.Add(entity);

                await context.SaveChangesAsync();

                return(PartnerContactErrorCodes.None);
            }
        }