Esempio n. 1
0
 public IActionResult GetJobTitlesByDepartmentId(int?id)
 {
     return(Ok(_cache.GetJobTitle(id, 1)));
 }
Esempio n. 2
0
        public async Task <IActionResult> Index(int templateId, DocumentFilterViewModel model = null)
        {
            if (templateId <= 0)
            {
                return(NotFound());
            }


            if (model == null)
            {
                model = new DocumentFilterViewModel();
            }

            model.TemplateId = templateId;

            var query = from d in Uow.Documents.GetAll()
                        join e in Uow.Employees.GetAll() on d.CreatorId equals e.Id//todo user and employee mapping table and auto initialize
                        select new DocumentsViewModel
            {
                Id           = d.Id,
                DepartmentId = d.DepartmentId,
                JobTitleId   = d.JobTitleId,


                CreateDate = d.CreateDate,
                CreatorId  = d.CreatorId,
                IsDeleted  = d.IsDeleted,

                IsApproved = d.IsApproved
            };


            query = query.Filter(q => q.Id, WhereOperator.Equals, model.Id);

            if (!User.IsInAnyRole(Constants.Roles.Admin, Constants.Roles.IT, Constants.Roles.Administration))
            {
                query = query.Filter(q => q.CreatorId, WhereOperator.Equals, UserId);
            }


            model.PagedList = await query.ToPagedListAsync(model.Page, model.PageSize);

            var jobTitles   = _cache.GetJobTitle(null, 1);
            var departments = _cache.GetDepartment(1);
            var branches    = _cache.GetBranch(1);

            foreach (var row in model.PagedList)
            {
                if (row.JobTitleId != null)
                {
                    row.JobTitle = jobTitles.TryGetValue(row.JobTitleId.Value);
                }
                if (row.DepartmentId != null)
                {
                    row.Department = departments.TryGetValue(row.DepartmentId.Value);
                }

                //if (row.BranchId != null)
                //    row.Branch = branches.TryGetValue(row.BranchId.Value);
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_Grid", model));
            }

            ReturnUrl = Url.Action(nameof(Index), "Documents", new { templateId });
            Title     = await Uow.DocumentTemplates.Where(t => t.Id == templateId && !t.IsDeleted).Select(t => t.Name).SingleOrDefaultAsync();

            return(View(model));
        }
Esempio n. 3
0
        public async Task <IActionResult> Index(EmployeeFilterViewModel model = null)
        {
            if (model == null)
            {
                model = new EmployeeFilterViewModel();
            }

            var query = Uow.Employees.GetAll().OrderByDescending(e => e.Id)
                        .Select(e => new EmployeesViewModel
            {
                Id           = e.Id,
                BranchId     = e.BranchId,
                JobTitleId   = e.JobTitleId,
                DepartmentId = e.DepartmentId,
                ImageUrl     = e.Image,

                FullName       = e.Person.FullName,
                PersonalNumber = e.Person.PersonalNumber,
                BirthDate      = e.Person.BirthDate,
                GenderId       = e.Person.GenderId,
                Branch         = e.Person.Contact.Phone1,

                Contact = new ContactBaseViewModel
                {
                    Id      = e.Person.ContactId,
                    Phone1  = e.Person.Contact.Phone1,
                    Mobile1 = e.Person.Contact.Mobile1,
                    Email1  = e.Person.Contact.Email1
                },

                IsDeleted = e.Person.IsDeleted,
            });

            query = query.Filter(q => q.IsDeleted, WhereOperator.Equals, false);
            query = query.Filter(q => q.Id, WhereOperator.Equals, model.Id);
            query = query.Filter(q => q.FullName, WhereOperator.Contains, model.FullName);
            query = query.Filter(q => q.Contact.Mobile1, WhereOperator.Contains, model.Mobile);
            query = query.Filter(q => q.Contact.Phone1, WhereOperator.Contains, model.Phone);


            query = query.Filter(q => q.JobTitleId, WhereOperator.Equals, model.JobTitleId);
            query = query.Filter(q => q.BranchId, WhereOperator.Equals, model.BranchId);
            query = query.Filter(q => q.DepartmentId, WhereOperator.Equals, model.DepartmentId);

            model.PagedList = await query.ToPagedListAsync(model.Page, model.PageSize);

            var jobTitles   = _cache.GetJobTitle(null, 1);
            var departments = _cache.GetDepartment(1);
            var branches    = _cache.GetBranch(1);

            foreach (var row in model.PagedList)
            {
                if (row.JobTitleId != null)
                {
                    row.JobTitle = jobTitles.TryGetValue(row.JobTitleId.Value);
                }
                if (row.DepartmentId != null)
                {
                    row.Department = departments.TryGetValue(row.DepartmentId.Value);
                }

                if (row.BranchId != null)
                {
                    row.Branch = branches.TryGetValue(row.BranchId.Value);
                }
            }


            if (Request.IsAjaxRequest())
            {
                return(PartialView("_Grid", model));
            }

            BindControls(model);
            Title = HrResources.Employees;

            return(View(model));
        }