public async Task <List <T> > List()
 {
     using ContextBase data = new ContextBase(_OptionBuilder);
     return(await data.Set <T>().ToListAsync());
 }
Beispiel #2
0
 public virtual TEntity Adicionar(TEntity entity)
 {
     _context.Set <TEntity>().Add(entity);
     _context.SaveChanges();
     return(entity);
 }
Beispiel #3
0
        public int Create(List <int> insertedViewElement, List <int> deletedviewElementRole, int roleId,
                          bool allowSaveChange = true)
        {
            var addedViewElemetId     = new List <int>();
            var allViewElements       = new List <ViewElement>();
            var allParentViewElements = new List <ViewElement>();

            var findedRole = ContextBase.Set <ViewElementRole>().Where(x => x.RoleId == roleId);

            var existedVElement = findedRole.Select(a => a.ViewElement.Id).ToList();

            //در دیتابیس هستند  در لیست حذف شده هم هست
            var deleteElement = from x in existedVElement
                                where deletedviewElementRole.Contains(x)
                                select x;

            //لیست آیتم هایی که در دیتابیس هست و قرار نیست حذف شود
            var fff =
                findedRole.Where(a => a.ViewElement.IsHidden != true)
                .Select(a => a.ViewElement.Id)
                .ToList();
            var existedItemForAdd = fff.Where(item => !deleteElement.Contains(item)).ToList();

            foreach (int item in existedItemForAdd)
            {
                if (!insertedViewElement.Contains(item))
                {
                    insertedViewElement.Add(item);
                }
            }

            foreach (var vId in existedVElement)
            {
                var findedVElement = ContextBase.Set <ViewElementRole>().FirstOrDefault(x => x.RoleId == roleId && x.ViewElementId == vId);
                if (findedVElement != null)
                {
                    ContextBase.Set <ViewElementRole>().Remove(findedVElement);
                }
            }

            foreach (var velementId in insertedViewElement)
            {
                //var foundVelement = ContextBase.Set<ViewElement>().Find(velementId);
                var founded = viewElementRepository.GetViewElementAndChildsById(velementId);
                if (founded.ChildrenViewElement != null)
                {
                    foreach (var childElement in founded.ChildrenViewElement)
                    {
                        var parentElement = viewElementRepository.GetViewElementAndChildsById(childElement.ParentId ?? 0);
                        List <ViewElement> resultElements;
                        resultElements = GetHiddenEelements(parentElement);
                        if (resultElements != null)
                        {
                            foreach (var resultElement in resultElements)
                            {
                                var hElement = ContextBase.Set <ViewElement>().Find(resultElement.Id);
                                if (!addedViewElemetId.Any(a => a.Equals(hElement.Id)))
                                {
                                    Create(new ViewElementRole()
                                    {
                                        RoleId        = roleId,
                                        ViewElementId = hElement.Id
                                    }, false);
                                }
                                //...
                                addedViewElemetId.Add(hElement.Id);
                                allViewElements.Add(founded);
                            }
                        }
                    }
                }

                //foundVelement.Roles.Add(findedRole);
                if (!addedViewElemetId.Any(a => a.Equals(founded.Id)))
                {
                    Create(new ViewElementRole()
                    {
                        RoleId        = roleId,
                        ViewElementId = founded.Id
                    }, false);
                }
                //...
                addedViewElemetId.Add(founded.Id);
                allViewElements.Add(founded);
            }

            //...

            foreach (var item in allViewElements)
            {
                if (!allViewElements.Any(r => r.Id == item.ParentId))
                {
                    var foundParent = ContextBase.Set <ViewElement>().Find(item.ParentId); //Find(item.ParentId);

                    if (foundParent != null)
                    {
                        if (!allParentViewElements.Any(a => a.Id == foundParent.Id))
                        {
                            allParentViewElements.Add(foundParent);
                        }
                    }
                }
            }

            foreach (var parent in allParentViewElements)
            {
                if (parent.ChildrenViewElement != null)
                {
                    var hiddenElements = parent.ChildrenViewElement.Where(a => a.IsHidden).ToList();
                    foreach (var hItem in hiddenElements)
                    {
                        // hItem.Roles.Add(findedRole);
                        if (!addedViewElemetId.Any(a => a.Equals(hItem.Id)))
                        {
                            Create(new ViewElementRole()
                            {
                                RoleId        = roleId,
                                ViewElementId = hItem.Id
                            }, false);
                        }
                        addedViewElemetId.Add(hItem.Id);
                        allViewElements.Add(hItem);
                    }
                }
            }
            var roles = findedRole.Select(x => x.Role).FirstOrDefault();

            if (roles != null)
            {
                ContextBase.Set <Role>().Attach(roles);
            }

            if (allowSaveChange)
            {
                // return ContextBase.SaveChanges();
                return(SaveChanges());
            }
            return(0);
        }
Beispiel #4
0
 public bool HasAdminRecord()
 {
     return(ContextBase.Set <UserProfile>().Any(a => a.UserName == GeneralConstant.AdminUserName));
 }
 public void Add(TEntity entity)
 {
     _dbContext.Set <TEntity>().Add(entity);
 }
Beispiel #6
0
 public Repositorio(ContextBase db)
 {
     Db    = db;
     DbSet = db.Set <T>();
 }
 public async Task <T> GetEntityById(int Id)
 {
     using (var data = new ContextBase(_OptionsBuild)) return(await data.Set <T>().FindAsync(Id));
 }
Beispiel #8
0
 public RepositoryGenerics(ContextBase context)
 {
     _contexto = context;
     DbSet     = _contexto.Set <T>();
 }
 protected Repository(ContextBase context)
 {
     Db    = context;
     DbSet = Db.Set <T>();
 }
        public int Create(List <int> inseretedCompanyViewElement, List <int> deletedCompanyViewElement, int CompanyId, bool allowSaveChange = true)
        {
            var addedViewElemetId     = new List <int>();
            var allViewElements       = new List <ViewElement>();
            var allParentViewElements = new List <ViewElement>();

            var foundedCompany = ContextBase.Set <Company>().Find(CompanyId);

            var existedVElement = foundedCompany.CompanyViewElements.Select(a => a.ViewElement.Id).ToList();

            //در دیتابیس هستند  در لیست حذف شده هم هست
            var deleteElement = from x in existedVElement
                                where deletedCompanyViewElement.Contains(x)
                                select x;

            //لیست آیتم هایی که در دیتابیس هست و قرار نیست حذف شود
            var neverDeleteItem =
                foundedCompany.CompanyViewElements.Where(a => a.ViewElement.IsHidden != true)
                .Select(a => a.ViewElement.Id)
                .ToList();
            var existedItemForAdd = neverDeleteItem.Where(item => !deleteElement.Contains(item)).ToList();


            foreach (int item in existedItemForAdd)
            {
                if (!inseretedCompanyViewElement.Contains(item))
                {
                    inseretedCompanyViewElement.Add(item);
                }
            }



            foreach (var vId in existedVElement)
            {
                var foundedViewElement = ContextBase.Set <CompanyViewElement>().Find(vId, CompanyId);
                ContextBase.Set <CompanyViewElement>().Remove(foundedViewElement);
            }


            foreach (var velementId in inseretedCompanyViewElement)
            {
                var foundVelement = ContextBase.Set <ViewElement>().Find(velementId);


                foreach (var childElement in foundVelement.ChildrenViewElement)
                {
                    var parentElement = ContextBase.Set <ViewElement>().Find(childElement.ParentId);
                    List <ViewElement> resultElements;
                    resultElements = GetHiddenEelements(parentElement);
                    if (resultElements != null)
                    {
                        foreach (var resultElement in resultElements)
                        {
                            var hElement = ContextBase.Set <ViewElement>().Find(resultElement.Id);
                            if (!addedViewElemetId.Any(a => a.Equals(hElement.Id)))
                            {
                                Create(new CompanyViewElement()
                                {
                                    CompanyId     = CompanyId,
                                    ViewElementId = hElement.Id
                                }, false);
                            }



                            //...
                            addedViewElemetId.Add(hElement.Id);
                            allViewElements.Add(foundVelement);
                        }
                    }
                }


                if (!addedViewElemetId.Any(a => a.Equals(foundVelement.Id)))
                {
                    Create(new CompanyViewElement()
                    {
                        CompanyId     = CompanyId,
                        ViewElementId = foundVelement.Id
                    }, false);
                }
                //...
                addedViewElemetId.Add(foundVelement.Id);
                allViewElements.Add(foundVelement);
            }


            //...

            foreach (var item in allViewElements)
            {
                if (!allViewElements.Any(r => r.Id == item.ParentId))
                {
                    var foundParent = ContextBase.Set <ViewElement>().Find(item.ParentId); //Find(item.ParentId);

                    if (foundParent != null)
                    {
                        if (!allParentViewElements.Any(a => a.Id == foundParent.Id))
                        {
                            allParentViewElements.Add(foundParent);
                        }
                    }
                }
            }

            foreach (var parent in allParentViewElements)
            {
                if (parent.ChildrenViewElement != null)
                {
                    var hiddenElements = parent.ChildrenViewElement.Where(a => a.IsHidden).ToList();
                    foreach (var hItem in hiddenElements)
                    {
                        if (!addedViewElemetId.Any(a => a.Equals(hItem.Id)))
                        {
                            Create(new CompanyViewElement()
                            {
                                CompanyId     = CompanyId,
                                ViewElementId = hItem.Id
                            }, false);
                        }
                        addedViewElemetId.Add(hItem.Id);
                        allViewElements.Add(hItem);
                    }
                }
            }

            ContextBase.Set <Company>().Attach(foundedCompany);
            if (allowSaveChange)
            {
                return(SaveChanges());
            }
            return(0);
        }
 public void Add(TEntity entity)
 {
     _context.Set <TEntity>().Add(entity);
     _context.SaveChanges();
 }
 public async Task AddAsync(T entity)
 {
     await _context.Set <T>().AddAsync(entity);
 }
Beispiel #13
0
 public RepositoryBase(ContextBase context)
 {
     Context = context;
     Set     = Context.Set <EntityType>();
 }
 public RepositoryBase(ContextBase context)
 {
     _context = context;
     DbSet    = _context.Set <TEntity>();
 }
 public async Task Update(T Object)
 {
     using ContextBase data = new ContextBase(_OptionBuilder);
     _ = data.Set <T>().Update(Object);
     _ = await data.SaveChangesAsync();
 }
Beispiel #16
0
 public IQueryable <CompanyChart> GetCompanyChart(int?id)
 {
     // var currentCMPchartId = UserLog.GetCompanyId();
     return(ContextBase.Set <CompanyChart>().Where(a => a.ParentId == id).Include("ChildCompanyChart").Include("CompanyChartRoles"));
 }
 public RepositoryBase(ContextBase contextBase)
 {
     _contextBase = contextBase;
     _dbSet       = contextBase.Set <TEntity>();
 }
        public async Task Add(T Objeto)
        {
            await _context.Set <T>().AddAsync(Objeto);

            await _context.SaveChangesAsync();
        }
Beispiel #19
0
 public CustomerRepository(ContextBase context)
 {
     Db    = context;
     DbSet = Db.Set <Customer>();
 }
 // GET: Cursos/Create
 public IActionResult Create()
 {
     ViewData["ProfessorId"] = new SelectList(_context.Set <Professor>(), "Id", "Nome");
     return(View());
 }
 public async Task <List <T> > List()
 {
     using (var data = new ContextBase(_OptionsBuild)) return(await data.Set <T>().AsNoTracking().ToListAsync());
 }
Beispiel #22
0
        //public int UpdateHeaderUser(User user, int currentOrganizationId, bool allowSaveChange = true)
        //{


        //    var CurrentUser = ContextBase.Set<User>().Find(user.Id);
        //    _dbContext.Entry(CurrentUser).CurrentValues.SetValues(user);
        //    foreach (var role in user.UserRoles.ToList())
        //    {

        //        var rep = new UserRoleRepository(_dbContext, UserLog);
        //        rep.Update(role, false);


        //    }


        //    if (allowSaveChange)
        //        return SaveChanges();
        //    return 0;


        //}

        public bool IsDuplicateUserName(string userName, int userId)
        {
            var useName = userName.Trim().CorrectPersianChars();

            return(ContextBase.Set <User>().Any(a => a.UserProfile.UserName == useName && a.Id != userId));
        }