Ejemplo n.º 1
0
        public static void DetachLocal <T>(this SODbContext context, T t, int entryId, EntityState state)
            where T : class, IIdentifier
        {
            var local = context.Set <T>()
                        .Local
                        .FirstOrDefault(entry => entry.Id.Equals(entryId));

            if (local != null)
            {
                context.Entry(local).State = EntityState.Detached;
            }

            context.Entry(t).State = state;
        }
Ejemplo n.º 2
0
        public bool Post(string value)
        {
            if (!value.IsNullOrWhiteSpace())
            {
                Random random       = new Random();
                int    randomNumber = random.Next(0, 10000000);
                var    p            = new Product
                {
                    DateCreated      = DateTime.UtcNow,
                    DateDiscontinued = null,
                    Id           = randomNumber,
                    InternalCode = "CODE_",
                    Name         = value
                };
                _context.Entry(p).State = EntityState.Detached;

                _context.Products.Add(p);
                _context.SaveChanges();
                return(true);
            }

            return(false);
        }