Exemple #1
0
        public async Task <List <ObjectResult <T> > > AddsAsync(List <T> entity)
        {
            List <ObjectResult <T> > result = new List <ObjectResult <T> >();

            foreach (var item in entity)
            {
                ObjectResult <T> added = new ObjectResult <T>();
                try
                {
                    using (VideoEntities context = new VideoEntities())
                    {
                        context.Entry(item).State = EntityState.Added;
                        await context.SaveChangesAsync();

                        added.obj = item;
                        added.status.OK();
                    }
                }
                catch (Exception ex)
                {
                    added.obj = item;
                    added.status.Error("Database Error", ex.Message);
                }
                result.Add(added);
            }
            return(result);
        }
Exemple #2
0
        public async Task <ServiceResult> RemoveAsync(T entity)
        {
            ServiceResult result = new ServiceResult();

            try
            {
                using (VideoEntities context = new VideoEntities())
                {
                    context.Entry(entity).State = EntityState.Deleted;
                    await context.SaveChangesAsync();

                    result.OK();
                }
            }
            catch (Exception ex)
            {
                result.Error("Database Error", ex.Message);
            }
            return(result);
        }
Exemple #3
0
        public async Task <ObjectResult <T> > AddAsync(T entity)
        {
            ObjectResult <T> result = new ObjectResult <T>();

            try
            {
                using (VideoEntities context = new VideoEntities())
                {
                    context.Entry(entity).State = EntityState.Added;
                    await context.SaveChangesAsync();

                    result.status.OK();
                    result.obj = entity;
                }
            }
            catch (Exception ex)
            {
                result.status.Error("Database Error", ex.Message);
            }
            return(result);
        }