internal static IContactAccount ToDomain(this ContactAccountModel contactAccountModel, IAccounting accounting, MapperCache mapperCache, IConverter accountingModelConverter) { NullGuard.NotNull(contactAccountModel, nameof(contactAccountModel)) .NotNull(accounting, nameof(accounting)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)); lock (mapperCache.SyncRoot) { IContactAccount contactAccount = contactAccountModel.Resolve(mapperCache.ContactAccountDictionary); if (contactAccount != null) { return(contactAccount); } IPaymentTerm paymentTerm = accountingModelConverter.Convert <PaymentTermModel, IPaymentTerm>(contactAccountModel.PaymentTerm); contactAccount = new ContactAccount(accounting, contactAccountModel.AccountNumber, contactAccountModel.BasicAccount.AccountName, paymentTerm) { Description = contactAccountModel.BasicAccount.Description, Note = contactAccountModel.BasicAccount.Note, MailAddress = contactAccountModel.MailAddress, PrimaryPhone = contactAccountModel.PrimaryPhone, SecondaryPhone = contactAccountModel.SecondaryPhone }; contactAccountModel.CopyAuditInformationTo(contactAccount); contactAccount.SetDeletable(contactAccountModel.Deletable); mapperCache.ContactAccountDictionary.Add(contactAccountModel.ContactAccountIdentifier, contactAccount); accounting.ContactAccountCollection.Add(contactAccount); contactAccount.ContactInfoCollection.Populate(contactAccount, contactAccountModel.StatusDate, contactAccountModel.StatusDateForInfos); if (contactAccountModel.PostingLines != null) { contactAccount.PostingLineCollection.Add(contactAccountModel.PostingLines .Where(postingLineModel => postingLineModel.Convertible() && postingLineModel.PostingDate >= contactAccountModel.GetFromDateForPostingLines() && postingLineModel.PostingDate < contactAccountModel.GetToDateForPostingLines(1)) .Select(postingLineModel => postingLineModel.ToDomain(accounting, contactAccount, mapperCache, accountingModelConverter)) .Where(postingLine => contactAccount.PostingLineCollection.Contains(postingLine) == false) .ToArray()); } return(contactAccount); } }
public async Task CreateContactAccountAsync_WhenCalled_CreatesContactAccount() { IAccountingRepository sut = CreateSut(); IAccounting accounting = await sut.GetAccountingAsync(WithExistingAccountingNumber(), DateTime.Today); IPaymentTerm[] paymentTermCollection = (await sut.GetPaymentTermsAsync()).ToArray(); IContactAccount contactAccount = new ContactAccount(accounting, WithExistingAccountNumberForContactAccount(), _fixture.Create <string>(), paymentTermCollection[_random.Next(0, paymentTermCollection.Length - 1)]) { Description = _fixture.Create <string>(), PrimaryPhone = _fixture.Create <string>() }; IContactAccount result = await sut.CreateContactAccountAsync(contactAccount); Assert.That(result, Is.Not.Null); }
public ActionResult CreateContactAccount(ContactAccount contactAccount) { contactAccount.Validate(ModelState, User); if (ModelState.IsValid) { if (contactAccount.CreateContactAccount()) { string description = ChangeLog.ContactAccount(contactAccount, db); ViewBag.Description = description; return(View("Success")); } ModelState.AddModelError("EmailAddress", "Failed to Create Contact Account"); } return(View(contactAccount)); }
internal static string ContactAccount(ContactAccount contactAccount, SNAPContext db) { try { ChangeLog changeLog = new ChangeLog(); changeLog.Timestamp = DateTime.Now; changeLog.Event = "Contact Account Created"; changeLog.Description = String.Format("{0} created", contactAccount.EmailAddress); changeLog.SubmittedBy = contactAccount.Creator; db.ChangeLogs.Add(changeLog); db.SaveChanges(); return(changeLog.Description); } catch (Exception) { return(null); } }