Ejemplo n.º 1
0
        public E save(E entity)
        {
            /*If there is an already persisted and deactivated entity
             * with a matching business identifier, then simply reactivate that entity*/
            E equalEntity = findDeactivatedEntityWithSameBusinessIdentifier(entity);

            if (equalEntity != null)
            {
                equalEntity.activate();
                dbContext.Entry(equalEntity).State = EntityState.Modified;
                dbContext.SaveChanges();
                return(equalEntity);
            }

            //*Avoid adding entities with the same business identifier
            //*A unique index could also work, but if the business identifier is a string,
            //*it's harder to ensure that field is case insensitive
            if (find(entity.id()) != null)
            {
                return(null);
            }

            dbContext.Set <E>().Add(entity);
            dbContext.SaveChanges();

            return(entity);
        }
        public CustomizedProductSerialNumber increment()
        {
            CustomizedProductSerialNumber serialNumber = findSerialNumber();

            serialNumber.incrementSerialNumber();

            dbContext.Entry(serialNumber).State = EntityState.Modified;
            dbContext.SaveChanges();

            return(serialNumber);
        }