Ejemplo n.º 1
0
        public static Partner ToDao(this AbstractEntities.NewPartner dto)
        {
            if (dto == null)
            {
                return(null);
            }

            return(new Partner
            {
                Address = dto.Address,
                Name = dto.Name
            });
        }
Ejemplo n.º 2
0
        public AbstractEntities.Partner CreatePartner(AbstractEntities.NewPartner newPartner)
        {
            if (newPartner == null)
            {
                throw new ArgumentNullException("newPartner");
            }

            lock (syncObject)
            {
                if (context.Partners.Any(p => string.Compare(p.Name, newPartner.Name, true) == 0))
                {
                    throw new RecordAlreadyExistsException($"Partner with name \"{newPartner.Name}\" already exists.");
                }

                var dao = newPartner.ToDao();
                context.Partners.Add(dao);
                context.SaveChanges();

                return(dao.ToAbstract());
            }
        }