예제 #1
0
        public GridResults LoadPaging(long userId, string search, int pageIndex, out long totalRecords, string sortColumnName = "", string sortOrderBy = "")
        {
            //Get current user
            var user = BlUser.LoadSingle(userId);

            //Query paged data
            var results = LoadPaging(userId, CreateFilter(search), user.PageSize, pageIndex - 1, out totalRecords);

            //Convert results into display model
            var res = (from r in results
                       select new
            {
                r.Id,
                Gender = r.Entity.Gender == null ? "" : BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "Gender", r.Entity.Gender)),
                Name = BlEntity.FormatFullName(r.Entity),
                Number = r.Entity.IdType == "M" ? r.Entity.IdNum : "",
                r.Entity.FullEnLongName,
                Level = r.Level == null ? "" : BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "EmployeeLevel", r.Level)),
                Status = r.Status == "A" ? "check colorGreen" : "close colorRed"
            }).ToList();


            //Convert display model into json data
            return(GridVm.FormatResult(res, user.PageSize, pageIndex, totalRecords));
        }
예제 #2
0
        private static DdlVm.DdlOption FormatForQs(int languageId, Employee item, bool returnPin = false)
        {
            var toRet = new DdlVm.DdlOption
            {
                value = returnPin ? item.Entity.Pin.ToUiString() : item.Id.ToUiString(),
                label = BlEntity.FormatFullName(item.Entity)
            };

            return(toRet);
        }
예제 #3
0
        public static List <DdlVm.DdlOption> LoadDdl(long userId, string parameters, string searchTerm, int pageSize, int pageNum, out long count)
        {
            var user     = BlUser.LoadSingle(userId);
            var blObject = new BlEntity();

            var serializer = new JavaScriptSerializer();
            var dict       = serializer.Deserialize <Dictionary <string, object> >(parameters);
            var isActive   = CheckEmpty.Boolean(ref dict, "isActive");
            var gender     = CheckEmpty.String(ref dict, "Gender");

            var predicate = PredicateBuilder.True <Entity>();

            if (isActive)
            {
                predicate = predicate.And(c => c.Status == "A");
            }

            if (gender != "")
            {
                predicate = predicate.And(c => gender.Split(',').Contains(c.Gender));
            }

            if (CheckEmpty.String(searchTerm) != "")
            {
                var predicate2 = PredicateBuilder.False <Entity>();
                predicate2 = predicate2.Or(m => m.FirstName.Contains(searchTerm));
                predicate2 = predicate2.Or(m => m.FatherName.Contains(searchTerm));
                predicate2 = predicate2.Or(m => m.FamilyName.Contains(searchTerm));
                predicate2 = predicate2.Or(m => m.ArFirstName.Contains(searchTerm));
                predicate2 = predicate2.Or(m => m.ArFatherName.Contains(searchTerm));
                predicate2 = predicate2.Or(m => m.ArFamilyName.Contains(searchTerm));
                predicate  = predicate.And(predicate2);
            }

            var items = blObject.LoadPaging(userId, predicate, pageSize, (pageNum - 1), out count);

            return(items.Select(i => FormatForDdl(user.LanguageId, i)).ToList());
        }
예제 #4
0
        public bool Delete(long userId, Address toDelete)
        {
            using (var tran = new TransactionScope())
            {
                var toRet = _repository.Delete(toDelete);

                BlLog.Log(userId, Module, "Delete address", "AddressDeleted", new object[] { toDelete.Sequence, toDelete.Entity.Pin, BlEntity.FormatFullName(toDelete.Entity) });
                tran.Complete();
                return(toRet);
            }
        }
예제 #5
0
        public Address Edit(long userId, Address toEdit)
        {
            using (var tran = new TransactionScope())
            {
                if (toEdit.EntryDate == DateTime.MinValue)
                {
                    toEdit.EntryDate = BlCommon.GetServerDateTime();
                }

                var toRet = _repository.Edit(toEdit);

                BlLog.Log(userId, Module, "Edit address", "AddressModified", new object[] { toEdit.Sequence, toEdit.Entity.Pin, BlEntity.FormatFullName(toEdit.Entity) });
                tran.Complete();
                return(toRet);
            }
        }
예제 #6
0
        public Address Create(long userId, Address toAdd)
        {
            using (var tran = new TransactionScope())
            {
                toAdd.EntryDate = BlCommon.GetServerDateTime();
                toAdd.UserId    = userId;
                toAdd.Sequence  = GetPinNextSequence(userId, toAdd.Entity.Pin);
                var toRet = _repository.Create(toAdd);

                BlLog.Log(userId, Module, "Create address", "AddressCreated", new object[] { toAdd.Sequence, toAdd.Entity.Pin, BlEntity.FormatFullName(toAdd.Entity) });
                tran.Complete();
                return(toRet);
            }
        }
예제 #7
0
        public bool Delete(long userId, Employee toDelete)
        {
            using (var tran = new TransactionScope())
            {
                //Check if employee has related user account
                if (BlUser.LoadByPin(userId, toDelete.Entity.Pin) != null)
                {
                    throw new BusinessException("CannotDeleteRelatedUser");
                }

                var toRet = _repository.Delete(toDelete);

                BlLog.Log(userId, Module, "Delete employee", "EmployeeDeleted", new object[] { toDelete.Entity.Pin, BlEntity.FormatFullName(toDelete.Entity) });
                tran.Complete();
                return(toRet);
            }
        }
예제 #8
0
        public Employee Edit(long userId, Employee toEdit)
        {
            using (var tran = new TransactionScope())
            {
                var toRet = _repository.Edit(toEdit);

                BlLog.Log(userId, Module, "Edit employee", "EmployeeModified", new object[] { toEdit.Entity.Pin, BlEntity.FormatFullName(toEdit.Entity) });
                tran.Complete();
                return(toRet);
            }
        }
예제 #9
0
        public Employee Create(long userId, Employee toAdd)
        {
            using (var tran = new TransactionScope())
            {
                toAdd.UserId    = userId;
                toAdd.EntryDate = BlCommon.GetServerDateTime();

                var toRet = _repository.Create(toAdd);

                BlLog.Log(userId, Module, "Create employee", "EmployeeCreated", new object[] { toAdd.Entity.Pin, BlEntity.FormatFullName(toAdd.Entity) });
                tran.Complete();
                return(toRet);
            }
        }