コード例 #1
0
        private int?GetGroupIdOfUser(string userId)
        {
            //Lấy ra groupId của user
            var grpIdOfUser = sysUserLevelRepo.Get(x => x.UserId == userId).FirstOrDefault()?.GroupId;

            return(grpIdOfUser);
        }
コード例 #2
0
        public SetTariffModel GetTariffById(Guid tariffId)
        {
            ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.settingTariff);
            var          permissionRangeWrite  = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.Write);
            var          permissionRangeDelete = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.Delete);


            var tariff = DataContext.Get(x => x.Id == tariffId).FirstOrDefault();
            var data   = mapper.Map <SetTariffModel>(tariff);

            BaseUpdateModel baseModel = new BaseUpdateModel
            {
                UserCreated  = data.UserCreated,
                CompanyId    = data.CompanyId,
                DepartmentId = data.DepartmentId,
                OfficeId     = data.OfficeId,
                GroupId      = data.GroupId
            };

            data.Permission = new PermissionAllowBase
            {
                AllowUpdate = PermissionExtention.GetPermissionDetail(permissionRangeWrite, baseModel, currentUser),
                AllowDelete = PermissionExtention.GetPermissionDetail(permissionRangeDelete, baseModel, currentUser),
            };

            data.UserCreatedName   = userRepository.Get(x => x.Id == data.UserCreated).FirstOrDefault()?.Username;
            data.UserModifieddName = userRepository.Get(x => x.Id == data.UserModified).FirstOrDefault()?.Username;

            return(data);
        }
コード例 #3
0
        public CatChargeAddOrUpdateModel GetChargeById(Guid id)
        {
            CatChargeAddOrUpdateModel returnCharge = new CatChargeAddOrUpdateModel();
            var charge            = DataContext.Get(x => x.Id == id).FirstOrDefault();
            var listChargeDefault = chargeDefaultRepository.Get(x => x.ChargeId == id).ToList();

            returnCharge.Charge = charge;

            // Update permission
            ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catCharge);
            var          permissionRangeWrite = PermissionExtention.GetPermissionRange(currentUser.UserMenuPermission.Write);

            BaseUpdateModel baseModel = new BaseUpdateModel
            {
                UserCreated  = returnCharge.Charge.UserCreated,
                CompanyId    = returnCharge.Charge.CompanyId,
                DepartmentId = returnCharge.Charge.DepartmentId,
                OfficeId     = returnCharge.Charge.OfficeId,
                GroupId      = returnCharge.Charge.GroupId
            };

            returnCharge.Permission = new PermissionAllowBase
            {
                AllowUpdate = PermissionExtention.GetPermissionDetail(permissionRangeWrite, baseModel, currentUser),
            };

            returnCharge.ListChargeDefaultAccount = listChargeDefault;

            return(returnCharge);
        }
コード例 #4
0
        public IQueryable <SysCompany> GetByUserId(string id)
        {
            var userLevels      = sysLevelRepository.Get(x => x.UserId == id).ToList();
            var lstSysCompanies = DataContext.Get(x => x.Active == true).ToList();
            var lsts            = lstSysCompanies.Where(item => userLevels.Any(uslv => uslv.CompanyId.Equals(item.Id)));

            return(lsts.AsQueryable());
        }
コード例 #5
0
        public IQueryable <SetTariffDetailModel> GetListTariffDetailByTariffId(Guid tariffId)
        {
            var tariffDetails = setTariffDetailRepo.Get(x => x.TariffId == tariffId);
            var charges       = catChargeRepo.Get();
            var commoditiGrps = catCommodityGroupRepo.Get();
            var payers        = catPartnerRepo.Get();
            var ports         = catPlaceRepo.Get(x => x.PlaceTypeId == CatPlaceConstant.Port);
            var warehouses    = catPlaceRepo.Get(x => x.PlaceTypeId == CatPlaceConstant.Warehouse);

            //var tariffDetailsModel = tariffDetails.ProjectTo<SetTariffDetailModel>(mapper.ConfigurationProvider);
            var queryData = from tariff in tariffDetails
                            join charge in charges on tariff.ChargeId equals charge.Id into charge2
                            from charge in charge2.DefaultIfEmpty()
                            join commoditiGrp in commoditiGrps on tariff.CommodityId equals commoditiGrp.Id into commoditiGrp2
                            from commoditiGrp in commoditiGrp2.DefaultIfEmpty()
                            join payer in payers on tariff.PayerId equals payer.Id into payer2
                            from payer in payer2.DefaultIfEmpty()
                            join port in ports on tariff.PortId equals port.Id into port2
                            from port in port2.DefaultIfEmpty()
                            join warehouse in warehouses on tariff.WarehouseId equals warehouse.Id into warehouse2
                            from warehouse in warehouse2.DefaultIfEmpty()
                            select new SetTariffDetailModel
            {
                Id               = tariff.Id,
                TariffId         = tariff.TariffId,
                ChargeId         = tariff.ChargeId,
                UseFor           = tariff.UseFor,
                Route            = tariff.Route,
                CommodityId      = tariff.CommodityId,
                PayerId          = tariff.PayerId,
                PortId           = tariff.PortId,
                WarehouseId      = tariff.WarehouseId,
                Type             = tariff.Type,
                RangeType        = tariff.RangeType,
                RangeFrom        = tariff.RangeFrom,
                RangeTo          = tariff.RangeTo,
                UnitPrice        = tariff.UnitPrice,
                Min              = tariff.Min,
                Max              = tariff.Max,
                NextUnit         = tariff.NextUnit,
                NextUnitPrice    = tariff.NextUnitPrice,
                UnitId           = tariff.UnitId,
                CurrencyId       = tariff.CurrencyId,
                Vatrate          = tariff.Vatrate,
                UserCreated      = tariff.UserCreated,
                DatetimeCreated  = tariff.DatetimeCreated,
                UserModified     = tariff.UserModified,
                DatetimeModified = tariff.DatetimeModified,
                ChargeName       = charge.ChargeNameEn,
                ChargeCode       = charge.Code,
                CommodityName    = commoditiGrp.GroupNameEn,
                PayerName        = payer.ShortName,
                PortName         = port.NameEn,
                WarehouseName    = warehouse.NameEn
            };

            return(queryData);
        }
コード例 #6
0
        public IQueryable <CatDepartmentModel> QueryData(CatDepartmentCriteria criteria)
        {
            var dept  = DataContext.Get();
            var query = from d in dept
                        join off in sysOfficeRepo.Get() on d.BranchId equals off.Id into off2
                        from off in off2.DefaultIfEmpty()
                        select new CatDepartmentModel
            {
                Id               = d.Id,
                Code             = d.Code,
                DeptName         = d.DeptName,
                DeptNameEn       = d.DeptNameEn,
                DeptNameAbbr     = d.DeptNameAbbr,
                Description      = d.Description,
                BranchId         = d.BranchId,
                OfficeName       = off.BranchNameEn,
                DeptType         = d.DeptType,
                UserCreated      = d.UserCreated,
                DatetimeCreated  = d.DatetimeCreated,
                UserModified     = d.UserModified,
                DatetimeModified = d.DatetimeModified,
                Active           = d.Active,
                InactiveOn       = d.InactiveOn
            };

            if (criteria.Type == "All" || string.IsNullOrEmpty(criteria.Type))
            {
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    //Search gần đúng
                    query = query.Where(x =>
                                        x.Code.IndexOf(criteria.Keyword ?? "", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                        x.DeptName.IndexOf(criteria.Keyword ?? "", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                        x.DeptNameEn.IndexOf(criteria.Keyword ?? "", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                        x.DeptNameAbbr.IndexOf(criteria.Keyword ?? "", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                        x.OfficeName.IndexOf(criteria.Keyword ?? "", StringComparison.OrdinalIgnoreCase) >= 0
                                        );
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    //Search gần đúng
                    query = query.Where(x =>
                                        criteria.Type == "Code" ? x.Code.IndexOf(criteria.Keyword ?? "", StringComparison.OrdinalIgnoreCase) >= 0 : true &&
                                        criteria.Type == "DeptName" ? x.DeptName.IndexOf(criteria.Keyword ?? "", StringComparison.OrdinalIgnoreCase) >= 0 : true &&
                                        criteria.Type == "DeptNameEn" ? x.DeptNameEn.IndexOf(criteria.Keyword ?? "", StringComparison.OrdinalIgnoreCase) >= 0 : true &&
                                        criteria.Type == "DeptNameAbbr" ? x.DeptNameAbbr.IndexOf(criteria.Keyword ?? "", StringComparison.OrdinalIgnoreCase) >= 0 : true &&
                                        criteria.Type == "OfficeName" ? x.OfficeName.IndexOf(criteria.Keyword ?? "", StringComparison.OrdinalIgnoreCase) >= 0 : true
                                        );
                }
            }

            var result = query.OrderByDescending(x => x.DatetimeModified);

            return(result);
        }
コード例 #7
0
        public IQueryable <SysGroupModel> Query(SysGroupCriteria criteria)
        {
            IQueryable <SysGroup>      groups      = null;
            IQueryable <CatDepartment> departments = null;

            if (criteria.All == null)
            {
                groups = DataContext.Get(x => (x.Code ?? "").IndexOf(criteria.Code ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                         (x.NameEn ?? "").IndexOf(criteria.NameEN ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                         (x.NameVn ?? "").IndexOf(criteria.NameVN ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                         (x.ShortName ?? "").IndexOf(criteria.ShortName ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                         (x.DepartmentId == criteria.DepartmentId || criteria.DepartmentId == 0) &&
                                         (x.Id == criteria.Id || criteria.Id == 0)
                                         );
                departments = departmentRepository.Get(x => (x.DeptNameEn ?? "").IndexOf(criteria.DepartmentName ?? "", StringComparison.OrdinalIgnoreCase) > -1);
            }
            else
            {
                groups = DataContext.Get(x => (x.Code ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 ||
                                         (x.NameEn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 ||
                                         (x.NameVn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 ||
                                         (x.ShortName ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1
                                         //|| (x.DepartmentId == criteria.DepartmentId || criteria.DepartmentId == 0)
                                         //|| (x.Id == criteria.Id || criteria.Id == 0)
                                         );
                departments = departmentRepository.Get(x => (x.DeptNameEn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1);
                if (departments.Count() == 0)
                {
                    departments = departmentRepository.Get();
                }
            }
            if (groups == null)
            {
                return(null);
            }
            groups = groups.Where(x => x.IsSpecial == false || x.IsSpecial == null);
            var results = groups.Join(departments, x => x.DepartmentId, y => y.Id, (x, y) => new SysGroupModel
            {
                Id               = x.Id,
                Code             = x.Code,
                NameEn           = x.NameEn,
                NameVn           = x.NameVn,
                ShortName        = x.ShortName,
                DepartmentId     = x.DepartmentId,
                ParentId         = x.ParentId,
                ManagerId        = x.ManagerId,
                UserCreated      = x.UserCreated,
                UserModified     = x.UserModified,
                DatetimeCreated  = x.DatetimeCreated,
                DatetimeModified = x.DatetimeModified,
                Active           = x.Active,
                InactiveOn       = x.InactiveOn,
                DepartmentName   = y.DeptNameEn
            }).OrderByDescending(x => x.DatetimeModified);

            return(results);
        }
コード例 #8
0
        public SysCompanyModel Get(Guid id)
        {
            var result = Get(x => x.Id == id)?.FirstOrDefault();

            if (result == null)
            {
                return(null);
            }
            else
            {
                result.NameUserCreated  = userRepository.Get(x => x.Id == result.UserCreated).FirstOrDefault()?.Username;
                result.NameUserModified = userRepository.Get(x => x.Id == result.UserModified).FirstOrDefault()?.Username;
                return(result);
            }
        }
コード例 #9
0
        public SysPermissionSampleModel GetBy(Guid?id)
        {
            var data   = DataContext.Get(x => x.Id == id).FirstOrDefault();
            var result = new SysPermissionSampleModel();

            if (data != null)
            {
                result = mapper.Map <SysPermissionSampleModel>(data);
            }
            result.SysPermissionSampleGenerals = permissionSampleGeneralService.GetBy(id);
            result.SysPermissionSampleSpecials = permissionSampleSpecialService.GetBy(id);
            result.NameUserCreated             = userRepository.Get(x => x.Id == result.UserCreated).FirstOrDefault()?.Username;
            result.NameUserModified            = userRepository.Get(x => x.Id == result.UserModified).FirstOrDefault()?.Username;
            return(result);
        }
コード例 #10
0
        private string GetManifestNo(Guid jobId)
        {
            string manifestNo = string.Empty;
            var    shipment   = transactionRepository.Get(x => x.Id == jobId).FirstOrDefault();
            //var prefixJob = shipment.JobNo.Substring(0, 3);
            int length = shipment.JobNo.Length - 1;

            switch (shipment.TransactionType)
            {
            case "SFI":
                manifestNo = "MSI" + shipment.JobNo.Substring(3);
                break;

            case "SFE":
                manifestNo = "MSE" + shipment.JobNo.Substring(3);
                break;

            case "SLE":
                manifestNo = "MSE" + shipment.JobNo.Substring(3);
                break;

            case "AE":
                manifestNo = "MAE" + shipment.JobNo.Substring(2);
                break;
            }
            return(manifestNo);
        }
コード例 #11
0
        public CsManifestModel GetById(Guid jobId)
        {
            var manifests = DataContext.Get(x => x.JobId == jobId);

            if (manifests.Count() == 0)
            {
                return(null);
            }
            var manifest = manifests.First();
            var places   = placeRepository.Get(x => x.PlaceTypeId.Contains("port"));
            var result   = mapper.Map <CsManifestModel>(manifest);

            result.PolName = places.FirstOrDefault(x => x.Id == manifest.Pol)?.NameEn;
            result.PodName = places.FirstOrDefault(x => x.Id == manifest.Pod)?.NameEn;
            return(result);
        }
コード例 #12
0
        private List <OpsStageAssignedModel> MapListToModel(IQueryable <OpsStageAssigned> data)
        {
            var stages      = catStageApi.GetAll().Result;
            var departments = catDepartmentApi.GetAll().Result;
            var users       = userRepository.Get();
            var results     = new List <OpsStageAssignedModel>();

            foreach (var item in data)
            {
                var stage        = stages?.FirstOrDefault(x => x.Id == item.StageId);
                var assignedItem = mapper.Map <OpsStageAssignedModel>(item);
                assignedItem.StageCode          = stage?.Code;
                assignedItem.StageNameEN        = stage?.StageNameEn;
                assignedItem.Status             = assignedItem.Status?.Trim();
                assignedItem.DepartmentName     = stage == null? null: departments?.FirstOrDefault(x => x.Id == stage.DepartmentId)?.DeptName;
                assignedItem.DoneDate           = item.Status?.Trim() == DataTypeEx.GetStageStatus(StageEnum.Done) ? item.DatetimeModified : null;
                assignedItem.Description        = assignedItem.Description ?? stages.FirstOrDefault(x => x.Id == item.StageId).DescriptionEn;
                assignedItem.MainPersonInCharge = assignedItem.MainPersonInCharge != null?users.FirstOrDefault(x => x.Id == assignedItem.MainPersonInCharge)?.Username : assignedItem.MainPersonInCharge;

                assignedItem.RealPersonInCharge = assignedItem.RealPersonInCharge != null?users.FirstOrDefault(x => x.Id == assignedItem.RealPersonInCharge)?.Username : assignedItem.RealPersonInCharge;

                results.Add(assignedItem);
            }
            return(results);
        }
コード例 #13
0
        List <MenuUserModel> ISysMenuService.GetMenus(string userId, Guid officeId)
        {
            var permissionId = userpermissionRepository.Get(x => x.UserId == userId && x.OfficeId == officeId)?.FirstOrDefault()?.Id;

            if (permissionId == null)
            {
                return(new List <MenuUserModel>());
            }
            var permissionMenus = permissionGeneralRepository.Get(x => x.UserPermissionId == permissionId && x.Access == true);

            var menus       = DataContext.Get(x => x.Id != null);
            var parentMenus = DataContext.Get(x => x.ParentId == null).ToList();
            var userMenus   = menus.Join(permissionMenus, x => x.Id, y => y.MenuId, (x, y) => x).ToList();

            userMenus.AddRange(parentMenus);
            var data = mapper.Map <List <MenuUserModel> >(userMenus);

            var results = FlatToHierarchy(data, null);

            if (results.Count > 0)
            {
                return(results.Where(x => x.SubMenus.Count > 0).ToList());
            }
            return(results);
        }
コード例 #14
0
        List <CsShipmentSurchargeDetailsModel> Query(Guid hbId, string type)
        {
            if (type == null)
            {
                type = string.Empty;
            }
            List <CsShipmentSurchargeDetailsModel> listCharges = new List <CsShipmentSurchargeDetailsModel>();
            var query = GetChargeByHouseBill(hbId, type, string.Empty);

            if (query.Count == 0)
            {
                return(listCharges);
            }
            foreach (var item in query)
            {
                var charge = mapper.Map <CsShipmentSurchargeDetailsModel>(item);
                charge.Currency     = item.CurrencyCode;
                charge.Unit         = item.UnitNameEn;
                charge.NameEn       = item.ChargeNameEn;
                charge.UnitCode     = item.UnitCode;
                charge.ExchangeRate = currencyExchangeService.CurrencyExchangeRateConvert(item.FinalExchangeRate, item.ExchangeDate, item.CurrencyId, DocumentConstants.CURRENCY_LOCAL);//item.RateToLocal;
                if (charge.Type == DocumentConstants.CHARGE_BUY_TYPE)
                {
                    charge.DebitCharge = catChargeRepository.Get(c => c.Id == charge.ChargeId).FirstOrDefault()?.DebitCharge;
                }
                listCharges.Add(charge);
            }
            return(listCharges);
        }
コード例 #15
0
        public IQueryable <SysUserViewModel> GetAll()
        {
            var users     = DataContext.Get(x => x.Active == true);
            var employees = employeeRepository.Get();
            var data      = users.Join(employees, x => x.EmployeeId, y => y.Id, (x, y) => new { x, y });
            List <SysUserViewModel> results = new List <SysUserViewModel>();

            foreach (var item in data)
            {
                var model = mapper.Map <SysUserViewModel>(item.x);
                model.EmployeeNameEn = item.y.EmployeeNameEn;
                model.EmployeeNameVn = item.y.EmployeeNameVn;
                results.Add(model);
            }
            return(results?.OrderBy(x => x.Username).AsQueryable());
        }
コード例 #16
0
        private SysGroup GetInfoGroupOfUser(string userId)
        {
            var grpIdOfUser   = GetGroupIdOfUser(userId);
            var infoGrpOfUser = sysGroupRepo.Get(x => x.Id == grpIdOfUser).FirstOrDefault();

            return(infoGrpOfUser);
        }
コード例 #17
0
        public IQueryable <SysPermissionSampleModel> Query(SysPermissionGeneralCriteria criteria)
        {
            IQueryable <SysPermissionSample> data = null;

            data = DataContext.Get(x => (x.Name ?? "").IndexOf(criteria.Name ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                   (x.RoleId == criteria.RoleId || criteria.RoleId == null) &&
                                   (x.Active == criteria.Active || criteria.Active == null)

                                   ).OrderByDescending(x => x.DatetimeModified);
            if (data == null)
            {
                return(null);
            }
            var roles   = roleRepository.Get().OrderByDescending(x => x.DatetimeModified);
            var results = data.Join(roles, x => x.RoleId, y => y.Id, (x, y) => new SysPermissionSampleModel {
                Id       = x.Id,
                Name     = x.Name,
                RoleId   = x.RoleId,
                Type     = x.Type,
                Active   = x.Active,
                RoleName = y.Name
            });

            return(results);
        }
コード例 #18
0
 public HandleState Delete(Guid id)
 {
     try
     {
         var hs = DataContext.Delete(x => x.Id == id, false);
         if (hs.Success)
         {
             var perGenerals = permissioSampleGeneralRepository.Get(x => x.PermissionId == id);
             foreach (var item in perGenerals)
             {
                 permissioSampleGeneralRepository.Delete(x => x.Id == item.Id, false);
             }
             var perSpecials = permissioSampleSpecialRepository.Get(x => x.PermissionId == id);
             foreach (var item in perSpecials)
             {
                 permissioSampleSpecialRepository.Delete(x => x.Id == item.Id, false);
             }
             DataContext.SubmitChanges();
             permissioSampleGeneralRepository.SubmitChanges();
             permissioSampleSpecialRepository.SubmitChanges();
         }
         return(hs);
     }
     catch (Exception ex)
     {
         var hs = new HandleState(ex.Message);
         return(hs);
     }
 }
コード例 #19
0
        public List <SysOffice> GetOfficePermission(string userId, Guid companyId)
        {
            try
            {
                var hs = new HandleState();
                List <SysOffice> results = null;

                var sysLevel = sysLevelRepository?.Get(lv => lv.UserId == userId && lv.CompanyId == companyId).Select(x => x.OfficeId).ToList();
                if (sysLevel == null)
                {
                    return(null);
                }
                if (sysLevel.Count() > 0)
                {
                    var sysOffice = DataContext.Get(o => sysLevel.Contains(o.Id)).ToList();
                    results = sysOffice;
                }

                return(results);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #20
0
        public List <SetEcusConnectionModel> GetConnections()
        {
            List <SetEcusConnectionModel> returnList = new List <SetEcusConnectionModel>();
            var cons      = Get().ToList();
            var users     = userRepository.Get();
            var employees = employeeRepository.Get();
            var query     = (from con in cons
                             join user in users on con.UserId equals user.Id
                             join em in employees on user.EmployeeId equals em.Id into grpEmployees
                             from employee in grpEmployees.DefaultIfEmpty()
                             select new { con, user.Username, employee?.EmployeeNameEn }
                             );

            if (query == null)
            {
                return(returnList);
            }
            foreach (var item in query)
            {
                SetEcusConnectionModel ecus = item.con;
                ecus.Username = item.Username;
                ecus.Fullname = item.EmployeeNameEn;
                returnList.Add(ecus);
            }
            return(returnList);
        }
コード例 #21
0
        public IQueryable <SysUserLevelModel> GetByUserId(string id)
        {
            var data        = DataContext.Get(x => x.UserId == id);
            var groups      = groupRepository.Get();
            var offices     = officeRepository.Get();
            var companies   = companyRepository.Get();
            var departments = departmentRepository.Get();
            var results     = from d in data
                              join g in groups on d.GroupId equals g.Id into groupss
                              from g in groupss.DefaultIfEmpty()
                              join o in offices on d.OfficeId equals o.Id into office
                              from o in office.DefaultIfEmpty()
                              join c in companies on d.CompanyId equals c.Id into company
                              from c in company.DefaultIfEmpty()
                              join depart in departments on d.DepartmentId equals depart.Id into departs
                              from depart in departs.DefaultIfEmpty()
                              select new SysUserLevelModel
            {
                CompanyId      = d.CompanyId,
                OfficeId       = d.OfficeId,
                DepartmentId   = d.DepartmentId,
                GroupId        = d.GroupId,
                GroupName      = g.NameVn,
                CompanyName    = c.BunameVn,
                OfficeName     = o.BranchNameVn,
                DepartmentName = depart.DeptName,
                Position       = d.Position
            };

            return(results);
        }
コード例 #22
0
        public CurrencyExchangeNewestViewModel GetExchangeRates(DateTime date, string localCurrency, string fromCurrency)
        {
            var users = userRepository.Get();
            var data  = DataContext.Get(x => x.DatetimeCreated.Value.Day == date.Day &&
                                        x.DatetimeCreated.Value.Month == date.Month &&
                                        x.DatetimeCreated.Value.Year == date.Year &&
                                        x.CurrencyToId == localCurrency &&
                                        (x.CurrencyFromId == fromCurrency || string.IsNullOrEmpty(fromCurrency)));

            var result = new CurrencyExchangeNewestViewModel();

            if (data.Count() == 0)
            {
                return(result);
            }
            var lastRate = data.OrderBy(x => x.DatetimeModified).ThenBy(x => x.DatetimeCreated).LastOrDefault();

            result.LocalCurrency    = localCurrency;
            result.DatetimeCreated  = date;
            result.DatetimeModified = date;
            string userName = string.Empty;

            if (lastRate.UserModified != null)
            {
                var userModified = users.FirstOrDefault(x => x.Id == lastRate.UserModified);
                userName = userModified != null ? userModified.Username : "******";
            }
            result.UserModifield = userName;

            result.ExchangeRates = new List <vw_catCurrencyExchangeNewest>();
            foreach (var item in data)
            {
                var rate = new vw_catCurrencyExchangeNewest
                {
                    CurrencyFromID  = item.CurrencyFromId,
                    Rate            = item.Rate,
                    DatetimeCreated = item.DatetimeModified
                };
                result.ExchangeRates.Add(rate);
            }
            result.ExchangeRates = result.ExchangeRates.OrderByDescending(x => x.DatetimeCreated).GroupBy(x => new { x.CurrencyFromID, x.Rate }).Select(x => new vw_catCurrencyExchangeNewest {
                CurrencyFromID = x.Key.CurrencyFromID, Rate = x.Key.Rate
            }).ToList();
            return(result);
        }
コード例 #23
0
        public IQueryable <CsMawbcontainerModel> Query(CsMawbcontainerCriteria criteria)
        {
            var containers = DataContext.Get(x => (x.Mblid == criteria.Mblid || criteria.Mblid == null) &&
                                             (x.Hblid == criteria.Hblid || criteria.Hblid == null));
            var containerTypes = catUnitRepository.Get(x => x.UnitType == "Container");
            var unitOfMeasures = catUnitRepository.Get(x => x.UnitType == "WeightMeasurement");
            var packageTypes   = catUnitRepository.Get(x => x.UnitType == "Package");
            var commodities    = catCommodityRepository.Get();
            var results        = (from container in containers
                                  join unitOfMeasure in unitOfMeasures on container.UnitOfMeasureId equals unitOfMeasure.Id into grpUnitOfMeasures
                                  from uOfMeasure in grpUnitOfMeasures.DefaultIfEmpty()
                                  join containerType in containerTypes on container.ContainerTypeId equals containerType.Id into grpContainerTypes
                                  from conType in grpContainerTypes.DefaultIfEmpty()
                                  join packageType in packageTypes on container.PackageTypeId equals packageType.Id into grpPackageTypes
                                  from packType in grpPackageTypes.DefaultIfEmpty()
                                  join commodity in commodities on container.CommodityId equals commodity.Id into grpCommodities
                                  from com in grpCommodities.DefaultIfEmpty()
                                  select new CsMawbcontainerModel {
                Id = container.Id,
                Mblid = container.Mblid,
                Hblid = container.Hblid,
                ContainerTypeId = container.ContainerTypeId,
                ContainerTypeName = conType.UnitNameEn,
                Quantity = container.Quantity,
                ContainerNo = container.ContainerNo,
                SealNo = container.SealNo,
                MarkNo = container.MarkNo,
                UnitOfMeasureId = container.UnitOfMeasureId,
                UnitOfMeasureName = uOfMeasure.UnitNameEn,
                CommodityId = container.CommodityId,
                CommodityName = com.CommodityNameEn,
                PackageTypeId = container.PackageTypeId,
                PackageTypeName = packType.UnitNameEn,
                PackageQuantity = container.PackageQuantity,
                Description = container.Description,
                Gw = container.Gw,
                Nw = container.Nw,
                Cbm = container.Cbm,
                ChargeAbleWeight = container.ChargeAbleWeight,
                UserModified = container.UserModified,
                DatetimeModified = container.DatetimeModified
            });

            return(results);
        }
コード例 #24
0
        public CatDepartmentModel GetDepartmentById(int id)
        {
            var data = new CatDepartmentModel();
            var dept = DataContext.Get(x => x.Id == id).FirstOrDefault();

            if (dept != null)
            {
                var off = sysOfficeRepo.Get(x => x.Id == dept.BranchId).FirstOrDefault();
                var com = sysCompanyRepo.Get(x => off != null && x.Id == off.Buid).FirstOrDefault();
                data                  = mapper.Map <CatDepartmentModel>(dept);
                data.CompanyId        = off != null ? off.Buid : Guid.Empty;
                data.OfficeName       = off != null ? off.BranchNameEn : "";
                data.CompanyName      = com != null ? com.BunameEn : "";
                data.UserNameCreated  = sysUserRepo.Get(x => x.Id == dept.UserCreated).FirstOrDefault()?.Username;
                data.UserNameModified = sysUserRepo.Get(x => x.Id == dept.UserModified).FirstOrDefault()?.Username;
            }
            return(data);
        }
コード例 #25
0
        public IQueryable <SysOffice> GetOffices()
        {
            var lstSysOffice = DataContext.Get();

            List <SysOfficeModel> resultData = new List <SysOfficeModel>();

            var sysCompany      = sysBuRepository.Get();
            var dataJoinCompany = (from office in lstSysOffice
                                   join company in sysCompany on office.Buid equals company.Id
                                   select new { office, companyName = company.BunameEn });

            foreach (var item in dataJoinCompany)
            {
                var office = mapper.Map <SysOfficeModel>(item.office);
                office.CompanyName = item.companyName;
                resultData.Add(office);
            }
            return(resultData?.OrderBy(x => x.ShortName).AsQueryable());
        }
コード例 #26
0
        public List <string> GetAuthorizedIds(string transactionType, ICurrentUser currentUser)
        {
            List <string> authorizeUserIds = authorizationRepository.Get(x => x.Active == true &&
                                                                         x.AssignTo == currentUser.UserID &&
                                                                         (x.EndDate ?? DateTime.Now.Date) >= DateTime.Now.Date &&
                                                                         x.Services.Contains(transactionType)
                                                                         )?.Select(x => x.UserId).ToList();

            return(authorizeUserIds);
        }
コード例 #27
0
        public IQueryable <SysUserLevelModel> GetByLevel(short groupId)
        {
            var userGroups = DataContext.Get(x => x.GroupId == groupId && x.Active == true);
            var users      = userRepository.Get();
            var employess  = employeeRepository.Get();
            var results    = userGroups.Join(users, x => x.UserId, y => y.Id, (x, y) => new { User = y, UserGroup = x })
                             .Join(employess, x => x.User.EmployeeId, y => y.Id, (x, y) => new { User = x, Employee = y })
                             .Select(x => new SysUserLevelModel
            {
                Id           = x.User.UserGroup.Id,
                UserId       = x.User.UserGroup.UserId,
                GroupId      = x.User.UserGroup.GroupId,
                UserName     = x.User.User.Username,
                EmployeeName = x.Employee.EmployeeNameVn,
                Active       = x.User.User.Active
            });

            return(results);
        }
コード例 #28
0
        public SysEmployeeModel GetByUser(string userId)
        {
            var user = userRepository.Get(x => x.Id == userId)?.FirstOrDefault();

            if (user == null)
            {
                return(null);
            }
            var employee = Get(x => x.Id == user.EmployeeId)?.FirstOrDefault();

            return(employee);
        }
コード例 #29
0
        public List <SysPermissionSampleSpecialViewModel> GetBy(Guid?permissionId)
        {
            var actionDefaults = specialActionRepository.Get().ToList();
            var modules        = actionDefaults.GroupBy(x => x.ModuleId);

            if (modules == null)
            {
                return(null);
            }
            var specialPermissions = DataContext.Get(x => x.PermissionId == permissionId);
            var menus = menuRepository.Get().ToList();

            List <SysPermissionSampleSpecialViewModel> results = new List <SysPermissionSampleSpecialViewModel>();

            foreach (var item in modules)
            {
                var specialP = new SysPermissionSampleSpecialViewModel();
                var module   = menus.FirstOrDefault(x => x.Id == item.Key);
                specialP.ModuleName   = module?.NameEn;
                specialP.ModuleID     = module?.Id;
                specialP.PermissionID = permissionId == null ? Guid.Empty : (Guid)permissionId;
                List <SysPermissionSpecialViewModel> sampleSpecials = new List <SysPermissionSpecialViewModel>();
                var actions       = actionDefaults.Where(x => x.ModuleId == item.Key);
                var actionsInMenu = actions.GroupBy(x => x.MenuId);
                foreach (var actionInMenu in actionsInMenu)
                {
                    var menu       = menus.FirstOrDefault(x => x.Id == actionInMenu.Key);
                    var perSpecial = new SysPermissionSpecialViewModel
                    {
                        MenuId       = menu?.Id,
                        MenuName     = menu?.NameEn,
                        PermissionId = permissionId == null ? Guid.Empty : (Guid)permissionId,
                        ModuleId     = item.Key
                    };
                    perSpecial.PermissionSpecialActions = actions.Where(x => x.MenuId == actionInMenu.Key)
                                                          .Select(x => new PermissionSpecialAction
                    {
                        Id           = (short)(specialPermissions.FirstOrDefault(s => s.MenuId == x.MenuId && s.ActionName == x.ActionName) != null ? (short)specialPermissions.FirstOrDefault(s => s.MenuId == x.MenuId && s.ActionName == x.ActionName).Id : 0),
                        ModuleId     = x.ModuleId,
                        MenuId       = x.MenuId,
                        NameEn       = x.NameEn,
                        NameVn       = x.NameVn,
                        ActionName   = x.ActionName,
                        IsAllow      = specialPermissions.FirstOrDefault(s => s.MenuId == x.MenuId && s.ActionName == x.ActionName) != null? specialPermissions.FirstOrDefault(s => s.MenuId == x.MenuId && s.ActionName == x.ActionName).IsAllow: false,
                        PermissionId = permissionId == null ? Guid.Empty : (Guid)permissionId
                    }).ToList();
                    sampleSpecials.Add(perSpecial);
                }
                specialP.SysPermissionSpecials = sampleSpecials;
                results.Add(specialP);
            }
            return(results);
        }
コード例 #30
0
        public IQueryable <CatDepartmentGroupCriteria> GetGroupDepartmentPermission(string userId, Guid officeId)
        {
            try
            {
                IQueryable <CatDepartmentGroupCriteria> results = null;
                // Các department user đc phân.
                var currentUserDepartments = sysLevelRepository.Get(lv => lv.UserId == userId && lv.OfficeId == officeId && lv != null)?.Select(l => l.DepartmentId).ToList();
                if (currentUserDepartments.Count() > 0)
                {
                    // các groups user đc phân
                    var currentUserGroups = sysLevelRepository.Get(lv => lv.UserId == userId && lv.DepartmentId == currentUserDepartments.First())?.Select(l => l.GroupId).ToList();
                    if (currentUserGroups.Count() > 0)
                    {
                        var query = from lv in sysLevelRepository.Get(lv => lv.UserId == userId && lv.OfficeId == officeId)
                                    join dp in departmentRepository.Get() on lv.DepartmentId equals dp.Id
                                    join sg in DataContext.Get() on lv.GroupId equals sg.Id
                                    select new CatDepartmentGroupCriteria
                        {
                            UserId         = lv.UserId,
                            DepartmentId   = (int)lv.DepartmentId,
                            DepartmentName = dp.DeptNameAbbr,
                            GroupId        = lv.GroupId,
                            GroupName      = sg.ShortName,
                        };
                        results = query;
                    }
                }
                else // user k có department | group.
                {
                    return(null);
                }

                return(results);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }