Ejemplo n.º 1
0
        public async Task <IActionResult> Approved()
        {
            AllowancesFilterViewModel viewModel = await BuildAllwancesFilterViewModel();

            viewModel.AllowanceViewModelList.RemoveAll(e => e.Status != ApprovedStatus.APPROVED);

            _viewModel = viewModel;
            _viewModel.IsFromFilter = false;
            return(View("Index", viewModel));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Pending()
        {
            AllowancesFilterViewModel viewModel = await BuildAllwancesFilterViewModel();

            viewModel.AllowanceViewModelList.RemoveAll(e => e.Status != ApprovedStatus.PENDING);

            _viewModel        = viewModel;
            ViewBag.IsPending = true;
            return(View("Index", viewModel));
        }
Ejemplo n.º 3
0
        // GET: Allowances
        public async Task <IActionResult> Index(Boolean IsFromFilter = false)
        {
            if (IsFromFilter)
            {
                return(await Filter(_viewModel));
            }
            AllowanceDates.Clear();
            AllowancesFilterViewModel viewModel = await BuildAllwancesFilterViewModel();

            _viewModel = viewModel;
            _viewModel.IsFromFilter = false;
            return(View(viewModel));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, AllowanceViewModel viewModel)
        {
            AllowancesFilterViewModel filter = _viewModel;
            var user = await userManager.GetUserAsync(HttpContext.User);

            if (id != viewModel.AllowanceID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var allowance = await _context.Allowance.FindAsync(id);

                    allowance.ModifiedOn     = DateTime.Now;
                    allowance.Description    = viewModel.Comments;
                    allowance.NumberOfDays   = AllowanceDates.Count();
                    allowance.AllowanceDates = JsonConvert.SerializeObject(AllowanceDates);
                    allowance.Price          = viewModel.Price;
                    allowance.Month          = viewModel.Month;
                    if (!string.IsNullOrEmpty(viewModel.ApprovedStatusId) && ((int)allowance.ApprovedStatus).ToString() != viewModel.ApprovedStatusId)
                    {
                        allowance.ApprovedStatus = Enum.GetValues(typeof(ApprovedStatus)).Cast <ApprovedStatus>().SingleOrDefault(e => ((int)e).ToString() == viewModel.ApprovedStatusId);
                    }
                    allowance.AllowanceType = _context.AllowanceType.SingleOrDefault(e => e.AllowanceTypeId.ToString() == viewModel.AllowanceTypeId);
                    allowance.Description   = viewModel.Comments;
                    allowance.Month         = Convert.ToDateTime(AllowanceDates.FirstOrDefault());
                    _context.Update(allowance);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AllowanceExists(viewModel.AllowanceID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                if (_viewModel.IsFromFilter || viewModel.IsFromFilter)
                {
                    return(await Filter(_viewModel));
                }
                return(RedirectToAction(nameof(Index)));
            }

            List <AllowanceType> allowanceTypes = _context.AllowanceType.Where(e => e.IsActive).ToList();

            List <AllowanceType> tempAllowanceTypes = new List <AllowanceType>();

            allowanceTypes.ForEach(model =>
            {
                model.catagoriesList = model.Categories != null ? JsonConvert.DeserializeObject <List <Category> >(model.Categories) : null;
                if (model.catagoriesList != null && model.catagoriesList.Exists(e => e.CategoryId == user.CategoryId))
                {
                    tempAllowanceTypes.Add(model);
                }
            });

            viewModel.AllowanceTypes = tempAllowanceTypes.Select(e => new SelectListItem
            {
                Text     = e.AllowanceTypeName,
                Value    = e.AllowanceTypeId.ToString(),
                Selected = e.AllowanceTypeId.ToString() == viewModel.AllowanceTypeId ? true : false
            }).ToList();
            viewModel.AllowanceTypesDetails = _context.AllowanceType.Where(e => e.IsActive).ToList();
            viewModel.ApprovedStatus        = Enum.GetValues(typeof(ApprovedStatus)).Cast <ApprovedStatus>().Select(v => new SelectListItem
            {
                Text     = v.ToString(),
                Value    = ((int)v).ToString(),
                Selected = ((int)v).ToString() == viewModel.ApprovedStatusId ? true : false
            }).ToList();
            return(View(viewModel));
        }
Ejemplo n.º 5
0
        public async Task <AllowancesFilterViewModel> GetFilter(AllowancesFilterViewModel viewModel)
        {
            var where = GetWhere(viewModel.AllowanceViewModel);
            var user = await userManager.GetUserAsync(HttpContext.User);

            List <Allowance> Allowance = null;

            if (User.IsInRole(Constants.ADMIN) || User.IsInRole(Constants.FINANCE))
            {
                Allowance = _context.Allowance.Where(where).Include(a => a.AllowanceType).Include(e => e.AssignedBy).Include(e => e.AssignedCategory).Include(e => e.CreatedBy).ToList();
            }
            else if (User.IsInRole(Constants.TL))
            {
                Allowance = _context.Allowance.Where(where).Include(a => a.AllowanceType).Include(e => e.AssignedBy).Include(e => e.AssignedCategory).Include(e => e.CreatedBy).Where(e => e.AssignedCategoryId == user.CategoryId).ToList();
            }
            else
            {
                Allowance = _context.Allowance.Where(where).Include(a => a.AllowanceType).Include(e => e.AssignedBy).Include(e => e.AssignedCategory).Include(e => e.CreatedBy).
                            Where(e => e.CreatedById == user.Id).ToList();
            }

            viewModel.AllowanceViewModelList        = GetAllowanceViewModel(Allowance);
            viewModel.AllowanceViewModel            = new AllowanceViewModel();
            viewModel.AllowanceViewModel.Categories = _context.Category.Where(e => e.IsActive).Select(e => new SelectListItem
            {
                Text     = e.CategoryName,
                Value    = e.CategoryId.ToString(),
                Selected = e.CategoryId.ToString() == viewModel.AllowanceViewModel.CategoryID ? true : false
            }).ToList();
            viewModel.AllowanceViewModel.Users = userManager.Users.Select(e => new SelectListItem
            {
                Text     = e.Name,
                Value    = e.Id,
                Selected = e.Id == viewModel.AllowanceViewModel.UserID ? true : false
            }).ToList();
            viewModel.AllowanceViewModel.ApprovedStatus = Enum.GetValues(typeof(ApprovedStatus)).Cast <ApprovedStatus>().Select(v => new SelectListItem
            {
                Text     = v.ToString(),
                Value    = ((int)v).ToString(),
                Selected = ((int)v).ToString() == viewModel.AllowanceViewModel.ApprovedStatusId ? true : false
            }).ToList();
            viewModel.AllowanceViewModel.AllowanceTypes = _context.AllowanceType.Where(e => e.IsActive).Select(e => new SelectListItem
            {
                Text  = e.AllowanceTypeName,
                Value = e.AllowanceTypeId.ToString()
            }).ToList();
            viewModel.AllowanceViewModel.Categories.Add(new SelectListItem {
                Text = "Select Category", Value = string.Empty, Selected = string.IsNullOrEmpty(viewModel.AllowanceViewModel?.CategoryID) ? true : false
            });
            viewModel.AllowanceViewModel.Users.Add(new SelectListItem {
                Text = "Select User", Value = string.Empty, Selected = string.IsNullOrEmpty(viewModel.AllowanceViewModel?.UserID) ? true : false
            });
            viewModel.AllowanceViewModel.ApprovedStatus.Add(new SelectListItem {
                Text = "Select Status", Value = string.Empty, Selected = string.IsNullOrEmpty(viewModel.AllowanceViewModel?.ApprovedStatusId) ? true : false
            });
            viewModel.AllowanceViewModel.AllowanceTypes.Add(new SelectListItem {
                Text = "Select Allowance Type", Value = string.Empty, Selected = string.IsNullOrEmpty(viewModel.AllowanceViewModel?.AllowanceTypeId) ? true : false
            });
            _viewModel = viewModel;
            _viewModel.IsFromFilter = true;
            return(viewModel);
        }
Ejemplo n.º 6
0
        public async Task <AllowancesFilterViewModel> BuildAllwancesFilterViewModel()
        {
            AllowancesFilterViewModel viewModel = new AllowancesFilterViewModel();
            var user = await userManager.GetUserAsync(HttpContext.User);

            var cygateWMSContext = _context.Allowance.Include(a => a.AllowanceType).Include(e => e.AssignedBy).Include(e => e.AssignedCategory).Include(e => e.CreatedBy)
                                   .Where(e => e.Month.Month == DateTime.Today.AddMonths(-1).Month).ToList();

            viewModel.AllowanceViewModel = await GetCreateViewModel();

            viewModel.AllowanceViewModel.Categories = _context.Category.Where(e => e.IsActive).Select(e => new SelectListItem
            {
                Text     = e.CategoryName,
                Value    = e.CategoryId.ToString(),
                Selected = e.CategoryId.ToString() == viewModel.AllowanceViewModel.CategoryID ? true : false
            }).ToList();
            viewModel.AllowanceViewModel.Users = userManager.Users.Where(e => e.CategoryId == user.CategoryId).Select(e => new SelectListItem
            {
                Text     = e.Name,
                Value    = e.Id,
                Selected = e.Id == viewModel.AllowanceViewModel.UserID ? true : false
            }).ToList();
            if (User.IsInRole(Constants.ADMIN))
            {
                viewModel.AllowanceViewModel.Users = userManager.Users.Select(e => new SelectListItem
                {
                    Text     = e.Name,
                    Value    = e.Id,
                    Selected = e.Id == viewModel.AllowanceViewModel.UserID ? true : false
                }).ToList();
            }
            viewModel.AllowanceViewModel.ApprovedStatus = Enum.GetValues(typeof(ApprovedStatus)).Cast <ApprovedStatus>().Select(v => new SelectListItem
            {
                Text     = v.ToString(),
                Value    = ((int)v).ToString(),
                Selected = ((int)v).ToString() == viewModel.AllowanceViewModel.ApprovedStatusId ? true : false
            }).ToList();
            viewModel.AllowanceViewModel.Categories.Add(new SelectListItem {
                Text = "Select Category", Value = string.Empty, Selected = string.IsNullOrEmpty(viewModel.AllowanceViewModel?.CategoryID) ? true : false
            });
            viewModel.AllowanceViewModel.Users.Add(new SelectListItem {
                Text = "Select User", Value = string.Empty, Selected = string.IsNullOrEmpty(viewModel.AllowanceViewModel?.UserID) ? true : false
            });
            viewModel.AllowanceViewModel.ApprovedStatus.Add(new SelectListItem {
                Text = "Select Status", Value = string.Empty, Selected = string.IsNullOrEmpty(viewModel.AllowanceViewModel?.ApprovedStatusId) ? true : false
            });

            if (User.IsInRole(Constants.ADMIN) || User.IsInRole(Constants.FINANCE))
            {
                viewModel.Users = _context.Users.Where(e => e.IsActive).ToList();
                viewModel.AllowanceViewModelList = GetAllowanceViewModel(cygateWMSContext).OrderBy(e => e.ApprovedStatus).ThenBy(e => e.CreatedOn).ToList();
            }
            else if (User.IsInRole(Constants.TL))
            {
                viewModel.AllowanceViewModelList = GetAllowanceViewModel(cygateWMSContext.Where(e => e.AssignedCategoryId == user.CategoryId).OrderBy(e => e.ApprovedStatus).ThenBy(e => e.CreatedOn).ToList());
            }
            else if (User.IsInRole(Constants.USER))
            {
                viewModel.AllowanceViewModelList = GetAllowanceViewModel(cygateWMSContext.Where(e => e.CreatedById == user.Id).OrderBy(e => e.ApprovedStatus).ThenBy(e => e.CreatedOn).ToList());
            }
            return(viewModel);
        }