Ejemplo n.º 1
0
        protected void SetEtag(TEntity entity, TModel model, string entityProperty)
        {
            var etag = (model as IProvideETag)?.ETag;

            if (etag != null)
            {
                Database.Entry(entity).Property(entityProperty).OriginalValue
                    = Convert.FromBase64String(etag);
            }
        }
Ejemplo n.º 2
0
        public async Task <User> Update(int id, User user)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var entity = await context.Users.FirstOrDefaultAsync(u => u.Id == id);

                    if (entity != null)
                    {
                        user.Password = Encryption.Encrypt(user.Password);
                        context.Entry(entity).CurrentValues.SetValues(user);
                        await context.SaveChangesAsync();

                        return(await Task.Run(() => user));
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public async Task Delete(int id)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var entity = await context.Categories.FirstOrDefaultAsync(c => c.Id == id);

                    if (entity != null)
                    {
                        context.Entry(entity).State = EntityState.Deleted;
                        await context.SaveChangesAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        public async Task <Category> Update(int id, Category category)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var entity = await context.Categories.FirstOrDefaultAsync(a => a.Id == id);

                    if (entity != null)
                    {
                        context.Entry(entity).CurrentValues.SetValues(category);
                        await context.SaveChangesAsync();

                        return(await Task.Run(() => category));
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 5
0
        public async Task <Document> Update(int id, Document document)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var entity = await context.Documents.FirstOrDefaultAsync(d => d.Id == id);

                    if (entity != null)
                    {
                        context.Entry(entity).CurrentValues.SetValues(document);
                        await context.SaveChangesAsync();

                        return(await Task.Run(() => document));
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }