protected Customer SaveCustomerDto(CustomerDto model, string subject, int eventTypeId, string notes = "", Event.EventStatus eventStatus = Event.EventStatus.Open, bool validateModel = true) { var customer = DbSession.GetCustomerByEmail(model.Email1); var newcustomer = customer == null; if (customer == null) { customer = CreateNewCustomer(); customer.EmailAddresses.Add(new CustomerEmailAddress { EmailAddress = model.Email1, Customer = customer }); customer.DefaultContact.Title = model.Title ?? ""; customer.DefaultContact.FirstName = model.FirstName; customer.DefaultContact.LastName = model.LastName; customer.DefaultContact.Email = model.Email1; customer.Name = String.IsNullOrWhiteSpace(model.CompanyName) ? customer.DefaultContact.FullName : model.CompanyName; DbSession.SaveOrUpdate(customer); DbSession.SaveOrUpdate(new Event { EventType = DbSession.Get <EventType>(1), Name = "New Customer", Status = Event.EventStatus.Final, Customer = customer, User = DbSession.CurrentUser(), RefID = customer.ID }); } model.UpdateCustomer(DbSession, customer); DbSession.SaveOrUpdate(new Event { EventType = DbSession.Get <EventType>(eventTypeId), Name = subject, Status = eventStatus, Customer = customer, User = DbSession.CurrentUser(), RefID = customer.ID, Notes = notes }); DbSession.Flush(); if (newcustomer) { customer.SetNumber(); DbSession.Flush(); } return(customer); }