public static Currency ToDao(this AbstractEntities.NewCurrency dto) { if (dto == null) { return(null); } return(new Currency { Code = dto.Code }); }
public AbstractEntities.Currency CreateCurrency(AbstractEntities.NewCurrency newCurrency) { if (newCurrency == null) { throw new ArgumentNullException("newCurrency"); } lock (syncObject) { if (context.Currencies.Any(c => string.Compare(c.Code, newCurrency.Code, true) == 0)) { throw new RecordAlreadyExistsException($"Currency with name \"{newCurrency.Code}\" already exists."); } var dao = newCurrency.ToDao(); context.Currencies.Add(dao); context.SaveChanges(); return(dao.ToAbstract()); } }