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(); } }
public async Task <PartnerContactErrorCodes> CreateIfNotExistsAsync(PartnerContactModel partnerContact) { var creationResult = await _partnerContactRepository.CreateIfNotExistAsync(partnerContact); if (creationResult == PartnerContactErrorCodes.PartnerContactAlreadyExists) { _log.Warning("Partner Contact already exists", context: partnerContact.LocationId); return(creationResult); } _log.Info("Partner Contact is created", context: partnerContact.LocationId); return(creationResult); }
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); } }
public async Task TryingToGetProfileContactByLocationId_ValidLocationId_SuccessfullyReturned() { var partnerContactRepository = new Mock <IPartnerContactRepository>(); var contactModel = new PartnerContactModel(); partnerContactRepository .Setup(x => x.GetByLocationIdAsync(It.IsAny <string>())) .ReturnsAsync(contactModel) .Verifiable(); PartnerContactService partnerContactService; using (var logFactory = LogFactory.Create().AddUnbufferedConsole()) { partnerContactService = new PartnerContactService( partnerContactRepository.Object, logFactory); } var actual = await partnerContactService.GetByLocationIdAsync("testContactId"); partnerContactRepository.Verify(); Assert.Equal(PartnerContactErrorCodes.None, actual.ErrorCode); }
public async Task CreateOrUpdateAsync(PartnerContactModel partnerContact) { await _partnerContactRepository.CreateOrUpdateAsync(partnerContact); _log.Info("Partner Contact is created or updated", context: partnerContact.LocationId); }