예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindowViewModel"/> class.
        /// </summary>
        /// <param name="modalDialogProvider">The modal dialog service.</param>
        /// <param name="serviceFactory">The service factory.</param>
        public UsersViewModel(IMainViewModel mainViewModel, IModalDialogProvider modalDialogProvider, IServiceFactory serviceFactory)
            : base(mainViewModel, modalDialogProvider, serviceFactory)
        {
            UserDetailsViewModel = new UserDetailsViewModel(MainViewModel, ModalDialogProvider, ServiceFactory);
              UserListViewModel = new UserListViewModel(MainViewModel, UserDetailsViewModel, ModalDialogProvider, ServiceFactory);

              RoleDetailsViewModel = new RoleDetailsViewModel(MainViewModel, ModalDialogProvider, ServiceFactory);
              RoleListViewModel = new RoleListViewModel(MainViewModel, RoleDetailsViewModel, ModalDialogProvider, ServiceFactory);
        }
예제 #2
0
        public ActionResult Index()
        {
            var permissions = _permissionAppService.GetAllPermissions()
                              .Items
                              .Select(p => new ComboboxItemDto(p.Name, new string('-', p.Level * 2) + " " + p.DisplayName))
                              .ToList();

            permissions.Insert(0, new ComboboxItemDto("", ""));
            var model = new RoleListViewModel
            {
                Permissions = permissions
            };

            return(View(model));
        }
        public async Task <IActionResult> Index(
            Guid?siteId,
            string searchInput = "",
            int pageNumber     = 1,
            int pageSize       = -1)
        {
            ISiteContext selectedSite;

            // only server admin site can edit other sites settings
            if ((siteId.HasValue) && (siteId.Value != Guid.Empty) && (siteId.Value != siteManager.CurrentSite.Id) && (siteManager.CurrentSite.IsServerAdminSite))
            {
                selectedSite = await siteManager.Fetch(siteId.Value) as ISiteContext;

                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, sr["{0} - Role Management"], selectedSite.SiteName);
            }
            else
            {
                selectedSite      = siteManager.CurrentSite;
                ViewData["Title"] = sr["Role Management"];
            }

            var model = new RoleListViewModel();

            model.SiteId = selectedSite.Id;

            int itemsPerPage = uiOptions.DefaultPageSize_RoleList;

            if (pageSize > 0)
            {
                itemsPerPage = pageSize;
            }

            var totalItems = await RoleManager.CountOfRoles(
                selectedSite.Id,
                searchInput);

            model.SiteRoles = await RoleManager.GetRolesBySite(
                selectedSite.Id,
                searchInput,
                pageNumber,
                itemsPerPage);

            model.Paging.CurrentPage  = pageNumber;
            model.Paging.ItemsPerPage = itemsPerPage;
            model.Paging.TotalItems   = totalItems;

            return(View(model));
        }
예제 #4
0
        public async Task <IActionResult> Modal(
            Guid?siteId,
            string searchInput = "",
            bool ajaxGrid      = false,
            int pageNumber     = 1,
            int pageSize       = -1)
        {
            var selectedSite = await _siteManager.GetSiteForDataOperations(siteId, true);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != _siteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, _sr["{0} - Role Management"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = _sr["Role Management"];
            }

            var model = new RoleListViewModel
            {
                SiteId = selectedSite.Id
            };

            int itemsPerPage = _uiOptions.DefaultPageSize_RoleList;

            if (pageSize > 0)
            {
                itemsPerPage = pageSize;
            }

            if (searchInput == null)
            {
                searchInput = string.Empty;
            }

            model.SiteRoles = await _roleManager.GetRolesBySite(
                selectedSite.Id,
                searchInput,
                pageNumber,
                itemsPerPage);

            if (ajaxGrid)
            {
                return(PartialView("ModalListPartial", model));
            }
            return(PartialView(model));
        }
예제 #5
0
        public IActionResult Index()
        {
            var roles     = _roleManager.Roles.OrderBy(r => r.Name).ToArray();
            var roleNames = new List <string>();

            foreach (var role in roles)
            {
                roleNames.Add(role.Name);
            }

            var model = new RoleListViewModel {
                Roles = roleNames
            };

            return(View(model));
        }
예제 #6
0
 public async Task <IActionResult> GetRoleList()
 {
     try
     {
         var model = new RoleListViewModel()
         {
             Roles = await GetRoles()
         };
         return(PartialView("_roles", model));
     }
     catch (Exception ex)
     {
         ex.ToExceptionless().Submit();
         return(BadRequest());
     }
 }
예제 #7
0
        public ActionResult Index()
        {
            var expression = new[]
            {
                new ExpressionCriteria {
                    PropertyName = "IsDel", Value = 0, Operate = Operator.Equal
                },
            };
            var rs        = _roleService.Get(expression);
            var viewModel = new RoleListViewModel
            {
                RoleContracts = rs,
            };

            return(View(viewModel));
        }
예제 #8
0
        public override void ExecuteResult(ControllerContext context)
        {
            base.ExecuteResult(context);

            int numOfRecords = 10; //TODO:

            var roles             = _roleRepository.GetRoles();
            var rolePageViewModel = new RoleListViewModel
            {
                Roles      = roles?.ToList(),
                PagingData = new PagingViewModel(_currentPage, _numOfPage, numOfRecords,
                                                 string.Format("{0}", "/Admin/Role/Index/{page}"), null)
            };

            GetViewResult(rolePageViewModel).ExecuteResult(context);
        }
        public async Task <ActionResult> Index()
        {
            var roles       = (await _roleAppService.GetAll(new PagedAndSortedResultRequestDto())).Items;
            var permissions = (await _roleAppService.GetAllPermissions()).Items;

            List <SysCategory> cateList = _roleAppService.GetSysCategoryAccordingRoleID();

            cateList.Remove(SysCategory.ALL);
            var model = new RoleListViewModel
            {
                Roles       = roles,
                Permissions = permissions,
                SysCateIDs  = cateList,
            };

            return(View(model));
        }
예제 #10
0
        public async Task <IActionResult> Index()
        {
            try
            {
                var model = new RoleListViewModel()
                {
                    Roles   = await GetRoles(),
                    RootUrl = BaseRootUrl
                };

                return(View(model));
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
                return(BadRequest());
            }
        }
예제 #11
0
        // GET: ApplicationUsers
        //public async Task<IActionResult> Index()
        //{
        //    List<IdentityRole> IdentityRolesLst = await _context.Roles.ToListAsync();
        //    List<ApplicationRoleDTO> ApplicationRoleDTOLst = new List<ApplicationRoleDTO>();
        //    ApplicationRoleDTOLst = _mapper.Map<List<ApplicationRoleDTO>>(IdentityRolesLst);

        //    return View(ApplicationRoleDTOLst);
        //}


        public IActionResult Index(int p = 1)
        {
            var currentPageNum = p;
            var offset         = (DefaultPageSize * currentPageNum) - DefaultPageSize;
            var model          = new RoleListViewModel();

            model.Roles.Data = this.allRolesDTO
                               .Skip(offset)
                               .Take(DefaultPageSize)
                               .ToList();

            model.Roles.PageNumber = currentPageNum;
            model.Roles.PageSize   = DefaultPageSize;
            model.Roles.TotalItems = allRolesDTO.Count;


            return(View(model));
        }
        public async Task <IActionResult> Delete(RoleListViewModel model)
        {
            try
            {
                await _roleService.RemoveAsync(model.Role.Id);

                ShowAlertSuccess($"Role \"{model.Role.Name}\" removed!");
            }
            catch (GraException gex)
            {
                ShowAlertDanger("Unable to remove Role: ", gex);
            }

            return(RedirectToAction(nameof(Index), new
            {
                page = model.PaginateModel.CurrentPage
            }));
        }
예제 #13
0
        public async Task <RoleListViewModel> PrepareListViewModelAsync(RoleSearchRequest request, bool isCurrentUser = false, Guid?userId = null)
        {
            request.CreatedById = await _commonService.GetUserIdAsync(isCurrentUser, userId);

            request.TotalCount = await _roleService.CountByRequestAsync(request);

            var role = await _roleService.GetRolesByRequestAsync(request);

            var roleViewModel = _mapper.Map <IList <RoleViewModel> >(role);
            var viewModel     = new RoleListViewModel
            {
                SearchRequest     = request,
                Roles             = roleViewModel,
                PageSizeList      = await _listManager.GetPageSizeListAsync(),
                SortDirectionList = await _listManager.GetSortDirectionListAsync(),
            };

            return(viewModel);
        }
        public async Task <IActionResult> Index(string msg)
        {
            ViewBag.menu = "UserRole";
            ViewBag.Msg  = msg;
            List <RoleListViewModel> result = new List <RoleListViewModel>();

            foreach (var item in _roleManager.Roles)
            {
                var listUser = await _userManager.GetUsersInRoleAsync(item.Name);

                RoleListViewModel newRoleList = new RoleListViewModel();
                newRoleList.ConcurrencyStamp    = item.ConcurrencyStamp;
                newRoleList.NormalizedRoleName  = item.NormalizedName;
                newRoleList.NumberOfUsersInRole = listUser.Count;
                newRoleList.RoleId   = item.Id;
                newRoleList.RoleName = item.Name;
                result.Add(newRoleList);
            }
            return(View(result));
        }
예제 #15
0
        public async Task <IActionResult> Index()
        {
            var adminManagementModel = new AdminManageViewModel();

            var userModel = new UserListViewModel
            {
                Users = _userManager.Users.OrderBy(x => x.UserName),
                Roles = _roleManager.Roles.OrderBy(x => x.OriginDate)
            };

            var roleModel = new RoleListViewModel()
            {
                Roles = await _adminService.GetRoles()
            };

            adminManagementModel.RoleListViewModel = roleModel;
            adminManagementModel.UserListViewModel = userModel;

            return(View(adminManagementModel));
        }
예제 #16
0
        public async Task <IActionResult> Index()
        {
            var roles       = (await _roleAppService.GetAll(new PagedAndSortedResultRequestDto())).Items;
            var permissions = (await _roleAppService.GetAllPermissions()).Items;

            foreach (var role in roles)
            {
                var grantedPermissions = (await _roleAppService.GetGrantedPermissionsAsync(role.Id));
                role.Permissions.Clear();
                role.Permissions.AddRange(grantedPermissions);
            }

            var model = new RoleListViewModel
            {
                Roles       = roles,
                Permissions = permissions
            };

            return(View(model));
        }
        public async Task <IActionResult> RoleList(string Key)
        {
            if (Key == null)
            {
                ModelState.AddModelError("IdHata", "Doğru bir arama değeri girmediniz!!");
            }

            // Bu kısımda input değeri değiştikçe arama değerinin değişmesini sağlayan bir method tanımla

            var model = new RoleListViewModel()
            {
                Roles = await _roleManager.Roles.Where(a => a.Name.Contains(Key)).ToListAsync <SchoolRole>()
            };

            if (model == null)
            {
                ModelState.AddModelError("AnythingRoleFind", "Can't Any Find Roles");
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
예제 #18
0
        public RoleListViewModel GetRoles(string account, string token)
        {
            //验证用户名和角色是否正确
            RoleListViewModel       rlvm = new RoleListViewModel();
            IEnumerable <RoleModel> list = _rr.FindBy(token);

            foreach (var item in list)
            {
                RoleViewModel rvm = new RoleViewModel()
                {
                    Id       = item.Id,
                    RoleName = item.RoleName,
                    Token    = item.Token,
                    IsAdmin  = item.IsAdmin
                };
                rlvm.list.Add(rvm);
            }
            rlvm.Success = true;
            rlvm.Message = "获取角色信息成功";
            return(rlvm);
        }
예제 #19
0
        public async Task <IActionResult> DeleteRole(string id)
        {
            var roleToDelete = await _context.Roles.FirstOrDefaultAsync(x => x.Id == id);

            var result = await _roleManager.DeleteAsync(roleToDelete);

            if (result.Succeeded)
            {
                await _context.SaveChangesAsync();

                CreateNotification("Role Deleted");

                var returnModel = new RoleListViewModel()
                {
                    Roles = await _adminService.GetRoles()
                };

                return(PartialView("_ListRolePartial", returnModel));
            }

            return(View("Index"));
        }
        public ActionResult Index()
        {
            //int userId = SessionProxy.UserId;
            //var account = new AccountController();
            //var currentUserRole = account.UserManager.GetRoles(User.Identity.GetUserId()).FirstOrDefault();
            int               userId          = SessionProxy.UserId;
            string            currentUserRole = _db.AspNetRoles.Where(x => x.AspNetUserRoles.Any(xx => xx.UserId == userId)).FirstOrDefault().Name;
            var               result          = _db.AspNetRoles.ToList();
            RoleListViewModel model           = new RoleListViewModel();

            foreach (var item in result)
            {
                if (item.Name != "SuperAdmin")
                {
                    RoleListViewModel m = new RoleListViewModel();
                    m.roleId   = item.Id;
                    m.roleName = item.Name;
                    model.RoleList.Add(m);
                }
            }
            return(View(model));
        }
예제 #21
0
        public virtual async Task <IActionResult> Index(
            Guid?siteId,
            string searchInput = "",
            int pageNumber     = 1,
            int pageSize       = -1)
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - Role Management"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["Role Management"];
            }

            var model = new RoleListViewModel
            {
                SiteId = selectedSite.Id
            };

            int itemsPerPage = UIOptions.DefaultPageSize_RoleList;

            if (pageSize > 0)
            {
                itemsPerPage = pageSize;
            }

            model.SiteRoles = await RoleManager.GetRolesBySite(
                selectedSite.Id,
                searchInput,
                pageNumber,
                itemsPerPage);

            return(View(model));
        }
예제 #22
0
        public ActionResult RoleList()
        {
            if (!_permissionService.Authorize(ThirdStorePermission.UserAccessControl.ToName()))
            {
                ErrorNotification("You do not have permission to process this page.");
                return(Redirect("~/"));
            }

            var model = new RoleListViewModel();

            model.YesOrNo = YesNo.Y.ToSelectList(false).ToList();
            model.YesOrNo.Insert(0, new SelectListItem {
                Text = "", Value = "-1", Selected = true
            });

            //var allowAccessUserList = new int[] { 1 };
            //if (!allowAccessUserList.Contains(_workContext.CurrentUser.ID))
            //{
            //    ErrorNotification("You do not have permission to process this page.");
            //    return Redirect("~/"); ;
            //}

            return(View(model));
        }
예제 #23
0
 public RoleDeleteCommand(RoleListViewModel rolLstVm)
 {
     viewModel = rolLstVm;
 }
예제 #24
0
        public IActionResult Edit(RoleListViewModel role)
        {
            _service.UpdateRole(role);

            return(RedirectToAction("List"));
        }
예제 #25
0
        private void MappingConfigurationBackOffice(IMapperConfigurationExpression cfg)
        {
            #region SystemConfiguration
            cfg.CreateMap <SystemConfiguration, SystemConfigurationViewModel>();
            #endregion


            #region FiscalYear
            cfg.CreateMap <FiscalYear, FiscalYearViewModel>()
            .ForMember(d => d.FiscalYearId, opts => opts.MapFrom(src => src.Id));
            #endregion


            #region LoginEmployee
            cfg.CreateMap <Employee, LoginEmployee>()
            .ForMember(d => d.UserId, opts => opts.MapFrom(src => src.AppUsers.Any() ? src.AppUsers.FirstOrDefault().Id : 0))
            .ForMember(d => d.Id, opts => opts.MapFrom(src => src.Id));
            #endregion

            #region RoleModule
            cfg.CreateMap <Role, RoleModel>();
            cfg.CreateMap <Permission, PermissionModel>()
            .AfterMap((src, dest) =>
            {
                dest.PermissionName        = src.Name;
                dest.PermissionDescription = src.Description;
            });
            #endregion RoleModule

            #region Role
            cfg.CreateMap <Role, RoleListViewModel>()
            .AfterMap((s, d) =>
            {
                RoleListViewModel role = new RoleListViewModel();
                d.Id   = s.Id;
                d.Role = s.Name.ConvertToSentence();
            });
            #endregion

            #region EmployeeProfile
            cfg.CreateMap <Employee, EmployeeProfileViewModel>()
            .ForMember(d => d.SectionName, opts => opts.MapFrom(src => src.Department.Name))
            .ForMember(d => d.DesignationName, opts => opts.MapFrom(src => src.Designation.Name))
            .ForMember(d => d.DateOfBirthBS, opts => opts.MapFrom(src => DateMiti.GetDateMiti.GetMiti(src.DateOfBirth)));
            cfg.CreateMap <EmployeeProfileViewModel, Employee>();

            #endregion EmployeeProfile

            #region Employee
            cfg.CreateMap <Employee, EmployeeViewModel>()
            .ForMember(d => d.DateOfBirthBS, opts => opts.MapFrom(src => DateMiti.GetDateMiti.GetMiti(src.DateOfBirth)));
            cfg.CreateMap <EmployeeViewModel, Employee>();
            cfg.CreateMap <Employee, EmployeeListViewModel>()
            .ForMember(d => d.DesignationName, opts => opts.MapFrom(src => src.Designation.Name))
            .ForMember(d => d.SectionName, opts => opts.MapFrom(src => src.Department.Name))
            .ForMember(d => d.UserName, opts => opts.MapFrom(src => src.AppUsers.Any() ? src.AppUsers.FirstOrDefault().UserName : null));

            #endregion Employee

            #region AppUser
            cfg.CreateMap <AppUser, AppUserViewModel>()
            .AfterMap((s, dest) =>
            {
                dest.Name       = s.EmployeeId.HasValue ? s.Employee.Name : null;
                dest.FullNameNP = s.EmployeeId.HasValue ? s.Employee.Name : null;
                dest.Email      = s.EmployeeId.HasValue ? s.Employee.Email : null;
            });

            cfg.CreateMap <AppUser, UserViewModel>()

            .AfterMap((s, d) =>
            {
                if (s.EmployeeId.HasValue)
                {
                    d.EmployeeId      = s.EmployeeId;
                    d.EmployeeName    = s.Employee.Name;
                    d.Email           = s.Employee.Email;
                    d.DesignationName = s.Employee.Designation.Name;
                }
                if (s.UserRoles.Any())
                {
                    d.Roles = s.UserRoles.Select(x => (int?)x.RoleId).ToArray();
                }
            });

            cfg.CreateMap <UserViewModel, AppUser>();

            cfg.CreateMap <AppUser, UserListViewModel>()
            .ForMember(d => d.Active, opts => opts.MapFrom(src => src.IsActive ? "Active" : "Passive"))
            .AfterMap((s, d) =>
            {
                if (s.EmployeeId.HasValue)
                {
                    d.EmployeeId   = s.EmployeeId;
                    d.EmployeeName = s.Employee.Name;
                    d.Email        = s.Employee.Email;
                }
                if (s.UserRoles.Any())
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var role in s.UserRoles)
                    {
                        sb.AppendFormat("{0}, ", role.Role.Name.ConvertToSentence());
                    }
                    d.RoleName = sb.ToString().Trim().Trim(',');
                }
            });
            #endregion AppUser

            #region LoginHostory
            cfg.CreateMap <LoginHistory, LoginHistoryViewModel>();
            cfg.CreateMap <LoginHistoryViewModel, LoginHistory>();
            #endregion


            #region Ims

            #region Ims Master

            #region Document Numbering
            cfg.CreateMap <DocumentNumbering, DocumentNumberingViewModel>();
            cfg.CreateMap <DocumentNumberingViewModel, DocumentNumbering>();

            cfg.CreateMap <DocumentNumbering, DocumentNumberingListViewModel>()
            .ForMember(d => d.DocumentSetupName, opts => opts.MapFrom(src => src.DocumentSetup.Name))
            .ForMember(d => d.FiscalYearName, opts => opts.MapFrom(src => src.FiscalYear.Name));
            #endregion Document Numbering

            #region ItemUnit
            cfg.CreateMap <ItemUnit, ItemUnitViewModel>();
            cfg.CreateMap <ItemUnitViewModel, ItemUnit>();

            cfg.CreateMap <ItemUnit, ItemUnitListViewModel>();
            #endregion ItemUnit

            #region Item
            cfg.CreateMap <Item, ItemViewModel>()
            .ForMember(d => d.ItemUnitName, opts => opts.MapFrom(src => src.ItemUnit.Name));
            cfg.CreateMap <ItemViewModel, Item>();

            cfg.CreateMap <Item, ItemListViewModel>()
            .ForMember(d => d.ItemGroupName, opts => opts.MapFrom(src => src.ItemGroup.Name))
            .ForMember(d => d.ItemUnitName, opts => opts.MapFrom(src => src.ItemUnit.Name))
            .ForMember(d => d.ItemTypeName, opts => opts.MapFrom(src => src.ItemGroup.ItemType.Name));
            #endregion Item

            #region Item Group
            cfg.CreateMap <ItemGroup, ItemGroupViewModel>().ForMember(d => d.ItemTypeAlias, opts => opts.MapFrom(src => src.ItemType.Alias));
            cfg.CreateMap <ItemGroupViewModel, ItemGroup>();

            cfg.CreateMap <ItemGroup, ItemGroupListViewModel>()
            .ForMember(d => d.ItemTypeName, opts => opts.MapFrom(src => src.ItemType.Name))
            .ForMember(d => d.IsFixed, opts => opts.MapFrom(src => src.ItemType.Alias == "Non-Consumable"));


            cfg.CreateMap <DepreciationRate, ItemGroupDepreciationRateViewModel>()
            .ForMember(d => d.FiscalYearName, opts => opts.MapFrom(src => src.FiscalYear.Name))
            .ForMember(d => d.ItemGroupName, opts => opts.MapFrom(src => src.ItemGroup.Name));

            cfg.CreateMap <ItemGroupDepreciationRateViewModel, DepreciationRate>();
            #endregion Item Group

            #region Vendor
            cfg.CreateMap <Vendor, VendorViewModel>();
            cfg.CreateMap <VendorViewModel, Vendor>();

            cfg.CreateMap <Vendor, VendorListViewModel>();
            #endregion Vendor


            #endregion Ims Master


            #region OpeningStock
            cfg.CreateMap <ItemReleaseDetail, TransactionItemViewModel>()
            .AfterMap((s, d) =>
            {
                d.ItemId   = s.ItemId;
                d.ItemCode = s.Item.Code;
                d.ItemName = s.Item.Name;
                d.Qty      = s.Qty;
            });

            cfg.CreateMap <ItemRequestDetail, TransactionItemViewModel>()
            .AfterMap((s, d) =>
            {
                d.ItemId   = s.ItemId;
                d.ItemCode = s.Item.Code;
                d.ItemName = s.Item.Name;
                d.Qty      = s.Qty;
            });


            cfg.CreateMap <StockTransaction, OpeningStockViewModel>()
            .ForMember(d => d.DateBS, opts => opts.MapFrom(src => src.Date.GetMiti()));
            cfg.CreateMap <OpeningStockViewModel, StockTransaction>()
            .ForMember(d => d.Date, opts => opts.MapFrom(src => src.DateBS.GetDate()));
            cfg.CreateMap <StockTransactionDetail, OpeningStockDetailViewModel>()
            .ForMember(d => d.PurchaseDateBS, opts => opts.MapFrom(src => src.PurchaseDate.GetMiti()))
            .ForMember(d => d.ItemName, opts => opts.MapFrom(src => src.Item.Name))
            .ForMember(d => d.UnitName, opts => opts.MapFrom(src => src.Item.ItemUnit.Name))
            .ForMember(d => d.SectionName, opts => opts.MapFrom(src => src.DepartmentId.HasValue ? src.Department.Name : null))
            .ForMember(d => d.EmployeeName, opts => opts.MapFrom(src => src.EmployeeId.HasValue ? src.Employee.Name : null))
            .ForMember(d => d.Amount, opts => opts.MapFrom(src => src.NetAmount))
            .ForMember(d => d.Narration, opts => opts.MapFrom(src => src.Remarks));

            cfg.CreateMap <OpeningStockDetailViewModel, StockTransactionDetail>()
            .ForMember(d => d.PurchaseDate, opts => opts.MapFrom(src => src.PurchaseDateBS.GetDate() == DateTime.MinValue ? (DateTime?)null : src.PurchaseDateBS.GetDate()))
            .ForMember(d => d.NetAmount, opts => opts.MapFrom(src => src.Amount))
            .ForMember(d => d.Remarks, opts => opts.MapFrom(src => src.Narration));

            cfg.CreateMap <StockTransaction, OpeningStockListViewModel>()
            .ForMember(d => d.NoOfItems, opts => opts.MapFrom(src => src.StockTransactionDetails.Count))
            .ForMember(d => d.DateBS, opts => opts.MapFrom(src => src.Date.GetMiti()))

            //new
            .ForMember(d => d.EmployeeDesignation, opts => opts.MapFrom(src => src.Employee.Designation.Name))
            .ForMember(d => d.EmployeeSection, opts => opts.MapFrom(src => src.Employee.Department.Name))
            .AfterMap((s, d) =>
            {
                d.ItemList = $"{s.StockTransactionDetails.FirstOrDefault().Item.Name}";
                d.ItemList = s.StockTransactionDetails.GroupBy(x => x.ItemId).Count() > 1 ? $"{d.ItemList} And other..." : d.ItemList;



                foreach (var item in s.StockTransactionDetails)
                {
                    d.Details.Add(Mapper.Map <ItemRequestDetailViewModel>(item));
                }
            });

            cfg.CreateMap <OpeningStockListViewModel, StockTransaction>();
            cfg.CreateMap <StockTransactionDetail, ItemRequestDetailViewModel>()
            .ForMember(d => d.ItemId, opts => opts.MapFrom(src => src.ItemId))
            .ForMember(d => d.ItemCode, opts => opts.MapFrom(src => src.Item.Code))
            .ForMember(d => d.ItemName, opts => opts.MapFrom(src => src.Item.Name))
            .ForMember(d => d.UnitName, opts => opts.MapFrom(src => src.Item.ItemUnit.Name))
            .ForMember(d => d.Remarks, opts => opts.MapFrom(src => src.Remarks));
            cfg.CreateMap <ItemRequestDetailViewModel, StockTransactionDetail>()
            .ForMember(d => d.Remarks, opts => opts.MapFrom(src => src.Remarks));


            #endregion OpeningStock

            #region Item Request
            cfg.CreateMap <ItemRequest, ItemRequestViewModel>()
            .ForMember(d => d.EmployeeDesignation, opts => opts.MapFrom(src => src.Employee.Designation.Name))
            .ForMember(d => d.EmployeeSection, opts => opts.MapFrom(src => src.Employee.Department.Name))
            .ForMember(d => d.DateBS, opts => opts.MapFrom(src => src.Date.GetMiti()))
            //.ForMember(d => d.AcceptedBy, opts => opts.MapFrom(src => src.Employee1 != null ? src.Employee1.Name : ""))
            //.ForMember(d => d.ItemReceivedBy, opts => opts.MapFrom(src => src.Employee2 != null ? src.Employee2.Name : ""))
            .AfterMap((s, d) =>
            {
                d.ItemList = $"{s.ItemRequestDetails.FirstOrDefault().Item.Name} ";
                d.ItemList = s.ItemRequestDetails.GroupBy(x => x.ItemId).Count() > 1 ? $"{d.ItemList } And other..." : d.ItemList;

                d.SectionName  = s.Department.Name;
                d.EmployeeName = s.Employee.Name;
                foreach (var item in s.ItemRequestDetails)
                {
                    d.Details.Add(Mapper.Map <ItemRequestDetailViewModel>(item));
                }
                //d.AnyItemsLeftForPurchaseOrder = s.ItemRequestDetails.Any(x => !x.PurchaseOrderId.HasValue && !x.ItemReleaseId.HasValue);
                //d.AnyItemsLeftToReleased = s.ItemRequestDetails.Any(x => !x.ItemReleaseId.HasValue);

                d.ItemRequestStatus = (int)eItemRequestStatus.Pending;
                if (s.ItemReleases.Any())
                {
                    var demand   = s.ItemRequestDetails.Sum(x => x.Qty);
                    var released = s.ItemReleases.Sum(x => x.ItemReleaseDetails.Sum(y => y.Qty));
                    if (demand > released)
                    {
                        d.ItemRequestStatus = (int)eItemRequestStatus.PartialReleased;
                    }
                    else
                    {
                        d.ItemRequestStatus = (int)eItemRequestStatus.Released;
                    }
                }
                else if (s.AcceptedBy.HasValue)
                {
                    d.ItemRequestStatus = (int)eItemRequestStatus.OnProcess;
                }
            });
            cfg.CreateMap <ItemRequestViewModel, ItemRequest>();
            cfg.CreateMap <ItemRequestDetail, ItemRequestDetailViewModel>()
            .ForMember(d => d.ItemCode, opts => opts.MapFrom(src => src.Item.Code))
            .ForMember(d => d.ItemName, opts => opts.MapFrom(src => src.Item.Name))
            .ForMember(d => d.UnitName, opts => opts.MapFrom(src => src.Item.ItemUnit.Name))
            .ForMember(d => d.Remarks, opts => opts.MapFrom(src => src.Remarks));
            cfg.CreateMap <ItemRequestDetailViewModel, ItemRequestDetail>()
            .ForMember(d => d.Remarks, opts => opts.MapFrom(src => src.Remarks));

            cfg.CreateMap <ItemRequestDetail, DashboardItemRequestViewModel>()
            .ForMember(d => d.RequestedDate, opts => opts.MapFrom(src => src.ItemRequest.Date))
            .ForMember(d => d.RequestedMiti, opts => opts.MapFrom(src => DateMiti.GetDateMiti.GetMiti(src.ItemRequest.Date)))
            .ForMember(d => d.RequestNo, opts => opts.MapFrom(src => src.ItemRequest.DisplayDocumentNo))
            .ForMember(d => d.Item, opts => opts.MapFrom(src => src.Item.Name))
            .ForMember(d => d.Status, opts => opts.MapFrom(src => Enum.GetName(typeof(eApplicationStatus), src.ItemRequest.ApplicationStatus)));
            #endregion

            #region PurchaseOrder
            cfg.CreateMap <PurchaseOrder, PurchaseOrderViewModel>()
            .ForMember(d => d.DateBS, opts => opts.MapFrom(src => src.Date.GetMiti()))
            .ForMember(d => d.DueDateBS, opts => opts.MapFrom(src => src.DueDate.GetMiti()));
            cfg.CreateMap <PurchaseOrderViewModel, PurchaseOrder>()
            .ForMember(d => d.Date, opts => opts.MapFrom(src => src.DateBS.GetDate()))
            .ForMember(d => d.DueDate, opts => opts.MapFrom(src => src.DueDateBS.GetDate()));
            cfg.CreateMap <PurchaseOrderDetail, PurchaseOrderDetailViewModel>()
            .AfterMap((src, d) =>
            {
                d.ItemId                 = src.ItemId;
                d.ItemCode               = src.Item.Code;
                d.ItemName               = src.Item.Name;
                d.UnitName               = src.Item.ItemUnit.Name;
                d.ItemRequestIdCSV       = src.PurchaseOrder.ItemRequestDetails != null ? string.Join(",", src.PurchaseOrder.ItemRequestDetails.Select(x => x.ItemRequestId)) : "";
                d.ItemRequestDetailIdCSV = src.PurchaseOrder.ItemRequestDetails != null ? string.Join(",", src.PurchaseOrder.ItemRequestDetails.Select(x => x.Id)) : "";
                d.Specification          = src.Remarks;
            });
            cfg.CreateMap <PurchaseOrderDetailViewModel, PurchaseOrderDetail>()
            .ForMember(d => d.Remarks, opts => opts.MapFrom(src => src.Specification));
            cfg.CreateMap <PurchaseOrder, PurchaseOrderListViewModel>()
            .AfterMap((s, d) =>
            {
                d.Vendor               = s.Vendor.Name;
                d.DateBS               = s.Date.GetMiti();
                d.NoOfItems            = s.PurchaseOrderDetails.Sum(x => x.Qty);
                d.IsPurchased          = s.StockTransactions.Any();
                d.ItemList             = $"{s.PurchaseOrderDetails.FirstOrDefault().Item.Name} ";
                d.ItemList             = s.PurchaseOrderDetails.Count > 1 ? $"{d.ItemList } And other..." : d.ItemList;
                d.FullEntry            = s.PurchaseOrderDetails.Sum(y => y.Qty) == s.StockTransactions.Sum(y => y.StockTransactionDetails.Sum(z => z.Qty));
                d.AcceptedEmployeeName = s.AcceptedBy.HasValue ? s.Employee.Name : null;
                using (var db = new UnitOfWork())
                {
                    var creater = db.EmployeeRepo.Table.Where(x => x.Id == s.EmployeeId).FirstOrDefault();
                    if (creater != null)
                    {
                        d.CreatedEmployeeName = creater.Name;
                    }
                }
                d.AcceptedDateBs = s.AcceptedDate.GetMiti();
                if (s.PurchaseOrderDetails.Any())
                {
                    foreach (var item in s.PurchaseOrderDetails)
                    {
                        d.Details.Add(new PurchaseOrderDetailViewModel
                        {
                            ItemId        = item.ItemId,
                            ItemName      = item.Item.Name,
                            UnitName      = item.Item.ItemUnit.Name,
                            Qty           = item.Qty,
                            Specification = item.Remarks
                        });
                    }
                }
            });
            cfg.CreateMap <ItemRequestDetailViewModel, PurchaseOrderDetailViewModel>()
            .ForMember(d => d.Specification, opts => opts.MapFrom(src => src.Remarks));
            #endregion

            #region ItemRelease
            cfg.CreateMap <ItemRelease, ItemReleaseViewModel>()
            .ForMember(d => d.DateBS, opts => opts.MapFrom(src => src.Date.GetMiti()));
            cfg.CreateMap <ItemReleaseViewModel, ItemRelease>()
            .ForMember(d => d.Date, opts => opts.MapFrom(src => src.DateBS.GetDate()));
            cfg.CreateMap <ItemReleaseDetail, ItemReleaseDetailViewModel>()
            .AfterMap((src, d) =>
            {
                d.ItemId                 = src.ItemId;
                d.ItemCode               = src.Item.Code;
                d.ItemName               = src.Item.Name;
                d.UnitName               = src.Item.ItemUnit.Name;
                d.ItemRequestIdCSV       = src.ItemRelease.ItemRequestDetails != null ? string.Join(",", src.ItemRelease.ItemRequestDetails.Select(x => x.ItemRequestId)) : "";
                d.ItemRequestDetailIdCSV = src.ItemRelease.ItemRequestDetails != null ? string.Join(",", src.ItemRelease.ItemRequestDetails.Select(x => x.Id)) : "";
            });
            cfg.CreateMap <ItemReleaseDetailViewModel, ItemReleaseDetail>();
            cfg.CreateMap <ItemRelease, ItemReleaseListViewModel>()
            .AfterMap((src, d) =>
            {
                d.DisplayRequestNo = src.ItemRequest.DisplayDocumentNo;
                d.DateBS           = src.Date.GetMiti();
                d.SectionName      = src.Department.Name;
                d.EmployeeName     = src.Employee.Name;
                d.ItemList         = src.ItemReleaseDetails.FirstOrDefault().Item.Name;
                d.ItemList         = src.ItemReleaseDetails.GroupBy(x => x.ItemId).Count() > 1 ? $"{d.ItemList } And other..." : d.ItemList;
            })
            .AfterMap((s, d) =>
            {
                d.IsAccepted = s.ItemRequest.ItemReceivedBy.HasValue;
            });
            cfg.CreateMap <ItemRequestDetailViewModel, ItemReleaseDetailViewModel>();
            #endregion

            #region PurchaseEntry
            cfg.CreateMap <StockTransaction, PurchaseEntryViewModel>()
            .ForMember(d => d.PurchaseOrderId, opts => opts.MapFrom(src => src.PurchaseOrderId))
            .ForMember(d => d.PurchaseOrderDisplayOrderNo, opts => opts.MapFrom(src => src.PurchaseOrderId.HasValue ? src.PurchaseOrder.DisplayDocumentNo : ""))
            .ForMember(d => d.PurchaseOrderDateBS, opts => opts.MapFrom(src => src.PurchaseOrderId.HasValue ? GetDateMiti.GetMiti(src.PurchaseOrder.Date) : ""))
            .ForMember(d => d.DateBS, opts => opts.MapFrom(src => src.Date.GetMiti()));
            cfg.CreateMap <PurchaseEntryViewModel, StockTransaction>()
            .ForMember(d => d.Date, opts => opts.MapFrom(src => src.DateBS.GetDate()));
            cfg.CreateMap <StockTransactionDetail, PurchaseEntryDetailViewModel>()
            .ForMember(d => d.ItemName, opts => opts.MapFrom(src => src.Item.Name))
            .ForMember(d => d.ItemCode, opts => opts.MapFrom(src => src.Item.Code))
            .ForMember(d => d.UnitName, opts => opts.MapFrom(src => src.Item.ItemUnit.Name))
            .ForMember(d => d.VatPerQty, opts => opts.MapFrom(src => src.Vat));
            cfg.CreateMap <PurchaseEntryDetailViewModel, StockTransactionDetail>()
            .ForMember(d => d.Vat, opts => opts.MapFrom(src => src.VatPerQty));

            cfg.CreateMap <StockTransaction, PurchaseEntryListViewModel>()
            .ForMember(d => d.NoOfItems, opts => opts.MapFrom(src => src.StockTransactionDetails.Count))
            .ForMember(d => d.DateBS, opts => opts.MapFrom(src => src.Date.GetMiti()))
            .AfterMap((s, d) =>
            {
                d.VendorName = s.Vendor != null ? s.Vendor.Name : null;
                if (s.StockTransactionDetails.Any())
                {
                    d.ItemList = $"{s.StockTransactionDetails.FirstOrDefault().Item.Name} ";
                    d.ItemList = s.StockTransactionDetails.GroupBy(x => x.ItemId).Count() > 1 ? $"{d.ItemList } And other..." : d.ItemList;
                }
            });
            #endregion PurchaseEntry

            #region StockAdjustment
            cfg.CreateMap <StockTransaction, StockAdjustmentViewModel>()
            .ForMember(d => d.DateBS, opts => opts.MapFrom(src => src.Date.GetMiti()));
            cfg.CreateMap <StockAdjustmentViewModel, StockTransaction>()
            .ForMember(d => d.Date, opts => opts.MapFrom(src => src.DateBS.GetDate()));

            cfg.CreateMap <StockTransactionDetail, StockAdjustmentDetailViewModel>().AfterMap((src, d) =>
            {
                d.ItemId       = src.ItemId;
                d.ItemName     = src.Item.Name;
                d.UnitName     = src.Item.ItemUnit.Name;
                d.SectionName  = src.Department.Name;
                d.EmployeeName = (src.EmployeeId.HasValue) ? src.Employee.Name : "";
                d.Narration    = src.Remarks;
            });
            cfg.CreateMap <StockAdjustmentDetailViewModel, StockTransactionDetail>()
            .ForMember(d => d.Remarks, opts => opts.MapFrom(src => src.Narration));

            cfg.CreateMap <StockTransaction, StockAdjustmentListViewModel>()
            //.ForMember(d => d.AdjustmentTypeName, opts => opts.MapFrom(src => src.AdjustmentType.Name))
            .ForMember(d => d.NoOfItems, opts => opts.MapFrom(src => src.StockTransactionDetails.Count));
            #endregion StockAdjustment
            #endregion Ims
        }
예제 #26
0
        public IActionResult Delete(RoleListViewModel role)
        {
            _service.DeleteRole(role.Id);

            return(RedirectToAction("List"));
        }
예제 #27
0
        public IActionResult GetList(TableRequest request, RoleListViewModel searchModel)
        {
            var response = _roleQueryService.Search(request, searchModel);

            return(new ApiResult(response));
        }
예제 #28
0
        public TableItems <RoleListViewModel[]> Search(TableRequest request, RoleListViewModel searchModel)
        {
            var query = _repository.TableAsNoTracking;

            IQueryable <TEntity> GetOrderedQuery <TEntity, TKey>(IQueryable <TEntity> localQuery, System.Linq.Expressions.Expression <Func <TEntity, TKey> > expression, string sortOrder)
            {
                return(sortOrder == "desc" ? localQuery.OrderByDescending(expression) : localQuery.OrderBy(expression));
            }

            //Zmień pierwszy znak kolumny do sortowania na wielką literę
            if (string.IsNullOrEmpty(request.sidx))
            {
                request.sidx = string.Empty;
            }
            else
            {
                char[] chars = request.sidx.ToCharArray();
                chars[0]     = char.ToUpper(chars[0]);
                request.sidx = new string(chars);
            }
            switch (request.sidx)
            {
            case nameof(Role.Name):
                query = GetOrderedQuery(query, q => q.Name, request.sord);
                break;

            case nameof(Role.Id):
                query = GetOrderedQuery(query, q => q.Id, request.sord);
                break;

            default:
                query = GetOrderedQuery(query, q => q.Name, request.sord);
                break;
            }

            if (!string.IsNullOrEmpty(searchModel.Name))
            {
                query = query.Where(w => w.Name.Contains(searchModel.Name));
            }
            if (searchModel.Id.HasValue)
            {
                query = query.Where(w => w.Id == searchModel.Id.Value);
            }

            var rows = query.Select(s => new RoleListViewModel
            {
                Name = s.Name,
                Id   = s.Id,
            });

            var total  = rows.Count();
            var toTake = request.rows;

            if (request.includePrevousPages)
            {
                toTake = request.page * request.rows;
            }
            else
            {
                rows = rows.Skip((request.page - 1) * request.rows);
            }
            var data = rows.Take(toTake).ToArray();

            return(new TableItems <RoleListViewModel[]>(data, total, request.page, (int)Math.Ceiling((decimal)total / request.rows)));
        }