Exemplo n.º 1
0
        public async Task <IActionResult> Index(int page = 1, string Name = null, DateTime?StartDate = null, DateTime?EndDate = null)
        {
            var model = new PermissionsGroupsViewModel
            {
                Name        = Name
                , StartDate = StartDate.HasValue ? ConvertDatetime.ConvertToGregorianDate(StartDate.Value) : StartDate
                , EndDate   = EndDate.HasValue ? ConvertDatetime.ConvertToGregorianDate(EndDate.Value) : EndDate
            };

            var permissionGroups = await permissionsGroupService.Search(Name, StartDate, EndDate);

            //if (permissionGroups.Count > 0)
            //{
            //    var List = mapper.Map<List<PermissionsGroupsViewModel>>(permissionGroups);
            //    model.PermissionsGroupsList = List.ToPagedList(page, Constants.PageSize);
            //}

            var List = mapper.Map <List <PermissionsGroupsViewModel> >(permissionGroups);

            model.PermissionsGroupsList = List.ToPagedList(page, Constants.PageSize);

            await model.FillLists(sessionService, adminsService);

            ViewBag.sessionService = sessionService;
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create()

        {
            var model = new PermissionsGroupsViewModel();
            await model.FillLists(sessionService, adminsService);

            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> PermissionsList(string id)
        {
            var model = new PermissionsGroupsViewModel();

            HttpContext.Session.SetString("GroupCode", id);
            model.PermissionsListValues = (await permissionsGroupService.GetPermissionListByGroupID(id)).Split(",").ToList();

            return(PartialView("_PermissionsList", model));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Create(PermissionsGroupsViewModel permissionsGroupsViewModel)
        {
            try
            {
                ModelState.Remove("Ger_StartDate");
                ModelState.Remove("Ger_EndDate");

                if (ModelState.IsValid)
                {
                    if (permissionsGroupsViewModel.EndDate < permissionsGroupsViewModel.StartDate)
                    {
                        TempData[Constants.ErrorMessage] = Messages.EndDateMustExceedStartDate;

                        //ModelState.AddModelError("EndDate", Messages.EndDateMustExceedStartDate);
                        return(View(permissionsGroupsViewModel));
                    }
                    #region Generate Random ID For Test

                    Random random                = new Random();
                    int    PermissionGroupId     = random.Next(1000);
                    string PermissionGroupPrefix = configuration.GetSection("AppSettings").GetSection("PermissionGroupPrefix").Value;
                    permissionsGroupsViewModel.Code = string.Concat(PermissionGroupPrefix, PermissionGroupId.ToString());

                    #endregion

                    var IsCodeExist = await permissionsGroupService.IsCodeExist(permissionsGroupsViewModel.Code);

                    if (IsCodeExist)
                    {
                        ModelState.AddModelError("Code", Messages.CodeAlreadyExists);
                        return(View(permissionsGroupsViewModel));
                    }

                    permissionsGroupsViewModel.PermissionsList = "test";

                    var PermissionGroup = mapper.Map <PermissionGroup>(permissionsGroupsViewModel);

                    await permissionsGroupService.Add(PermissionGroup, sessionService.User.Id);

                    TempData[Constants.SuccessMessage] = Messages.CreateSuccess;

                    return(RedirectToAction("Index", "PermissionsGroup"));
                }

                return(View(permissionsGroupsViewModel));
            }
            catch (Exception ex)
            {
                TempData[Constants.ErrorMessage] = Messages.ResourceManager.GetString(ex.Message);

                return(View(permissionsGroupsViewModel));
            }
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Edit(PermissionsGroupsViewModel permissionsGroupsViewModel)
        {
            try
            {
                var _permissionGroups = await permissionsGroupService.GetPermissionGroupById(permissionsGroupsViewModel.Code);

                if (_permissionGroups == null)
                {
                    return(NotFound());
                }

                ModelState.Remove("Ger_StartDate");
                ModelState.Remove("Ger_EndDate");

                if (ModelState.IsValid)
                {
                    if (permissionsGroupsViewModel.EndDate < permissionsGroupsViewModel.StartDate)
                    {
                        TempData[Constants.ErrorMessage] = Messages.EndDateMustExceedStartDate;

                        //ModelState.AddModelError("EndDate", Messages.EndDateMustExceedStartDate);
                        return(View(permissionsGroupsViewModel));
                    }
                    // var PermissionGroups = mapper.Map<PermissionGroup>(permissionsGroupsViewModel);
                    var permissionGroups = _permissionGroups;
                    permissionGroups.Name      = permissionsGroupsViewModel.Name;
                    permissionGroups.StartDate = (DateTime)permissionsGroupsViewModel.StartDate;
                    permissionGroups.EndDate   = (DateTime)permissionsGroupsViewModel.EndDate;
                    permissionGroups.ViewSecretTransactions = permissionsGroupsViewModel.ViewSecretTransactions;

                    await permissionsGroupService.Update(permissionGroups);

                    await loggingService.LogActionData <PermissionGroup>(LoggingCategory.PermissionGroup, LoggingAction.Edit,
                                                                         _permissionGroups, permissionGroups, sessionService.User.Id, _permissionGroups.Code);



                    TempData[Constants.SuccessMessage] = Messages.EditSuccess;

                    return(RedirectToAction("Index", "PermissionsGroup"));
                }

                return(View(permissionsGroupsViewModel));
            }
            catch (Exception ex)
            {
                TempData[Constants.ErrorMessage] = Messages.ResourceManager.GetString(ex.Message);

                return(View(permissionsGroupsViewModel));
            }
        }