private List <CustomerDTO> LstCustomer(List <CustomerGift> lst, string phanhe, List <User> lstUser)
 {
     return(lst.Select(p => new CustomerDTO
     {
         Id = p.Id,
         Status = p.Status,
         CusId = p.CusId,
         Acctno = p.Acctno,
         CusName = p.CusName,
         TERM = p.TERM,
         TERMCD = p.TERMCD,
         INTRATE = p.INTRATE,
         RATECD = p.RATECD,
         BALANCE = p.BALANCE,
         CCYCD = p.CCYCD,
         FRDATE = p.FRDATE,
         TODATE = p.TODATE,
         CREATEDDATE = p.CREATEDDATE,
         CREATEDBy = ContextProvider.GetFullName(lstUser, p.CREATEDBy),
         TENLOAIHINH = p.TENLOAIHINH,
         ACTYPE = p.ACTYPE,
         CHEQUENO = p.CHEQUENO,
         LICENSE = p.LICENSE,
         SUBBRID = p.SUBBRID,
         SUBBRNAME = p.SUBBRNAME,
         BRANCHID = p.BRANCHID,
         BRNAME = p.BRNAME,
         PhanHe = phanhe.ToUpper()
     }).ToList());
 }
Exemple #2
0
        public dynamic Get(int pageNo, int pageSize, string textSearch, string typeGift, string groupGift)
        {
            dynamic lstResults = new ExpandoObject();

            textSearch = string.IsNullOrWhiteSpace(textSearch) ? "" : textSearch;
            SessionManager.DoWork(ss =>
            {
                try
                {
                    var lstUser = ss.Query <User>().ToList();
                    var lstGift = ss.QueryOver <Gift>()
                                  .Where(p => p.Name.IsLike(textSearch, MatchMode.Anywhere)).OrderBy(p => p.CreatedDate).Desc.List();
                    if (!string.IsNullOrEmpty(typeGift) && lstGift.Count > 0)
                    {
                        lstGift = lstGift.Where(p => p.GiftGroup.OptionGift.Name == typeGift).ToList();
                    }
                    if (!string.IsNullOrEmpty(groupGift) && lstGift.Count > 0)
                    {
                        lstGift = lstGift.Where(p => p.GiftGroup.Name == groupGift).ToList();
                    }
                    var giftIds               = lstGift.Select(s => s.Id).Distinct().ToList();
                    var giftPromotions        = ss.Query <GiftPromotion>().Where(p => giftIds.Contains(p.GiftId)).ToList();
                    var giftPromotionIds      = giftPromotions.Select(s => s.GiftPromotionId).ToList();
                    var promotions            = ss.Query <Promotion>().Where(p => giftPromotionIds.Contains(p.GiftPromotionId)).ToList();
                    lstResults.ListGiftOutput =
                        lstGift.Skip((pageNo - 1) * pageSize).Take(pageSize)
                        .Select(p => new
                    {
                        p.Id,
                        p.Code,
                        p.Name,
                        GiftGroupId    = p.GiftGroup.Id,
                        GiftGroupCode  = p.GiftGroup.Code,
                        GiftGroupName  = p.GiftGroup.Name,
                        OptionGiftId   = p.GiftGroup.OptionGift.Id,
                        OptionGiftCode = p.GiftGroup.OptionGift.Code,
                        OptionGiftName = p.GiftGroup.OptionGift.Name,
                        UnitId         = p.Unit.Id,
                        UnitCode       = p.Unit.Code,
                        UnitName       = p.Unit.Name,
                        p.Price,
                        IsEdit      = !promotions.Any(a => giftPromotions.Where(w => w.GiftId == p.Id).Select(s => s.GiftPromotionId).ToList().Contains(a.GiftPromotionId)),
                        CreatedBy   = ContextProvider.GetFullName(lstUser, p.CreatedBy),
                        CreatedDate = ContextProvider.GetConvertDatetime(p.CreatedDate),
                        UpdatedBy   = ContextProvider.GetFullName(lstUser, p.UpdatedBy),
                        UpdatedDate = ContextProvider.GetConvertDatetime(p.UpdatedDate)
                    }).ToList();
                    var total            = lstGift.Count();
                    lstResults.TotalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            });
            return(lstResults);
        }
Exemple #3
0
        public dynamic Get(int pageNo, int pageSize, string textSearch, int sltPermisionId, string dateSearch)
        {
            dynamic lstResults = new ExpandoObject();

            textSearch = string.IsNullOrWhiteSpace(textSearch) ? "" : textSearch;
            dateSearch = string.IsNullOrWhiteSpace(dateSearch) ? "" : dateSearch;
            SessionManager.DoWork(ss =>
            {
                try
                {
                    var lstUser = ss.Query <User>().ToList();
                    var lstGG   = ss.QueryOver <GiftGroup>()
                                  .Where(p => p.Name.IsLike(textSearch, MatchMode.Anywhere) ||
                                         p.Code.IsLike(textSearch, MatchMode.Anywhere)).OrderBy(p => p.CreatedDate).Desc.List();
                    if (sltPermisionId != 0)
                    {
                        var userForPermision = lstUser.Where(w => w.PermisionId == sltPermisionId).Select(w => w.Id).ToList();
                        lstGG = lstGG.Where(w => userForPermision.Contains(w.CreatedBy.Value)).ToList();
                    }
                    if (dateSearch != "")
                    {
                        DateTime oDate = Convert.ToDateTime(dateSearch);
                        lstGG          = lstGG.Where(w => oDate.ToString("yyyy-MM-dd") == w.CreatedDate.Value.ToString("yyyy-MM-dd")).ToList();
                    }

                    lstResults.ListGiftGroupOutput =
                        lstGG.Skip((pageNo - 1) * pageSize).Take(pageSize)
                        .Select(p => new
                    {
                        p.Id,
                        p.Code,
                        p.Name,
                        OptionGiftId   = p.OptionGift.Id,
                        OptionGiftCode = p.OptionGift.Code,
                        OptionGiftName = p.OptionGift.Name,
                        CreatedBy      = ContextProvider.GetFullName(lstUser, p.CreatedBy),
                        CreatedDate    = ContextProvider.GetConvertDatetime(p.CreatedDate),
                        UpdatedBy      = ContextProvider.GetFullName(lstUser, p.UpdatedBy),
                        UpdatedDate    = ContextProvider.GetConvertDatetime(p.UpdatedDate),
                        p.Status
                    }).ToList();
                    var total            = lstGG.Count();
                    lstResults.TotalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            });
            return(lstResults);
        }
Exemple #4
0
        public dynamic GetDetail(Guid id)
        {
            dynamic result = new ExpandoObject();

            try
            {
                SessionManager.DoWork(ss =>
                {
                    var lstUser           = ss.Query <User>().ToList();
                    var gift              = ss.Get <Gift>(id);
                    var giftPromotionIds  = ss.Query <GiftPromotion>().Where(p => p.GiftId == id).Select(s => s.GiftPromotionId).ToList();
                    var isEdit            = !ss.Query <Promotion>().Any(p => giftPromotionIds.Contains(p.GiftPromotionId));
                    result.Id             = gift.Id;
                    result.Code           = gift.Code;
                    result.Name           = gift.Name;
                    result.GiftGroupId    = gift.GiftGroup.Id;
                    result.GiftGroupCode  = gift.GiftGroup.Code;
                    result.GiftGroupName  = gift.GiftGroup.Name;
                    result.OptionGiftId   = gift.GiftGroup.OptionGift.Id;
                    result.OptionGiftCode = gift.GiftGroup.OptionGift.Code;
                    result.OptionGiftName = gift.GiftGroup.OptionGift.Name;
                    result.Price          = gift.Price;
                    result.UnitId         = gift.Unit.Id;
                    result.UnitCode       = gift.Unit.Code;
                    result.UnitName       = gift.Unit.Name;
                    result.IsEdit         = isEdit;
                    result.CreatedBy      = ContextProvider.GetFullName(lstUser, gift.CreatedBy);
                    result.CreatedDate    = gift.CreatedDate;
                    result.UpdatedDate    = gift.UpdatedDate;
                    result.UpdatedBy      = ContextProvider.GetFullName(lstUser, gift.UpdatedBy);
                });
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result);
        }
Exemple #5
0
        public dynamic Get(int pageNo, int pageSize, string textSearch)
        {
            dynamic lstResults = new ExpandoObject();

            textSearch = string.IsNullOrWhiteSpace(textSearch) ? "" : textSearch;
            SessionManager.DoWork(ss =>
            {
                try
                {
                    var lstUser = ss.Query <User>().ToList();
                    var lstUnit = ss.QueryOver <Unit>()
                                  .Where(p => p.Name.IsLike(textSearch, MatchMode.Anywhere) ||
                                         p.Code.IsLike(textSearch, MatchMode.Anywhere)).OrderBy(p => p.CreatedDate).Desc.List();
                    lstResults.ListUnitOutput =
                        lstUnit.Skip((pageNo - 1) * pageSize).Take(pageSize)
                        .Select(p => new
                    {
                        p.Id,
                        p.Code,
                        p.Name,
                        CreatedBy   = ContextProvider.GetFullName(lstUser, p.CreatedBy),
                        CreatedDate = ContextProvider.GetConvertDatetime(p.CreatedDate),
                        UpdatedBy   = ContextProvider.GetFullName(lstUser, p.UpdatedBy),
                        UpdatedDate = ContextProvider.GetConvertDatetime(p.UpdatedDate)
                    }).ToList();
                    lstResults.Total     = lstUnit.Count();
                    var total            = lstUnit.Count();
                    lstResults.TotalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            });
            return(lstResults);
        }
        public dynamic DetailTangQua(string id)
        {
            dynamic result = new ExpandoObject();

            try
            {
                SessionManager.DoWork(ss =>
                {
                    var idCusGift = new Guid(id);
                    var lstUser   = ss.Query <User>().ToList();
                    result        = ss.Query <CustomerGift>().Where(s => s.ParentId == idCusGift).ToList().GroupBy(p => new
                    {
                        PromotionId = p.Promotion.Id,
                        p.ParentId,
                        p.CusId,
                        p.PhanHe,
                        p.Acctno,
                        p.TENLOAIHINH,
                        p.CusName,
                        p.TERM,
                        p.TERMCD,
                        p.BALANCE,
                        p.CCYCD,
                        p.FRDATE,
                        p.TODATE,
                        p.NgayDuyet,
                        p.NguoiDuyet,
                        p.Status,
                        p.CREATEDBy,
                        p.CREATEDDATE
                    }).Select(p => new
                    {
                        Id = p.Key.ParentId,
                        p.Key.CusId,
                        p.Key.CusName,
                        p.Key.Acctno,
                        p.Key.TERM,
                        p.Key.TERMCD,
                        p.Key.TENLOAIHINH,
                        p.Key.BALANCE,
                        p.Key.PhanHe,
                        p.Key.CCYCD,
                        p.Key.FRDATE,
                        p.Key.TODATE,
                        PromotionId   = p.Key.PromotionId,
                        PromotionName = ss.Get <Promotion>(p.Key.PromotionId)?.Name,
                        PromotionCode = ss.Get <Promotion>(p.Key.PromotionId)?.Code,
                        GiftKH        = p.ToList().Select(s => new
                        {
                            GiftCode   = s.Gift.Code,
                            GiftName   = s.Gift.Name,
                            GiftId     = s.Gift.Id,
                            UnitName   = s.Gift.Unit.Name,
                            Price      = s.Gift.Price,
                            TotalPrice = (s.Gift.Price * s.NumGift),
                            NumGift    = s.NumGift,
                        }).ToList(),
                        CreatedDate = p.Key.CREATEDDATE != null ? p.Key.CREATEDDATE.Value.ToString("yyyy-MM-dd hh:mm") : "",
                        CreatedBy   = ContextProvider.GetFullName(lstUser, p.Key.CREATEDBy),
                        DonViTang   = ContextProvider.GetDonViTang(lstUser, p.Key.CREATEDBy),
                        NgayDuyet   = p.Key.NgayDuyet != null ? p.Key.NgayDuyet.Value.ToString("yyyy-MM-dd hh:mm") : "",
                        NguoiDuyet  = ContextProvider.GetFullName(lstUser, p.Key.NguoiDuyet),
                        p.Key.Status
                    }).FirstOrDefault();
                });
            }
            catch (Exception ex)
            {
                result = ex;
            }
            return(result);
        }
        public dynamic LstKhachHangNhanQua(string phanhe, string acctno, string promotionId, int pageNo, int pageSize, ClaimsPrincipal principal)
        {
            dynamic result = new ExpandoObject();

            try
            {
                SessionManager.DoWork(s =>
                {
                    var userinfo     = ContextProvider.GetUserInfo(principal);
                    var typeUser     = ContextProvider.CheckPermission(userinfo.PermisionId);
                    var lstPromotion = s.Query <Promotion>().ToList();
                    var lstUser      = s.Query <User>().ToList();
                    var idUsers      = lstUser.Where(w => w.Organization.Id == userinfo.Organization.Id).Select(u => u.Id).ToList();
                    var list         = s.Query <CustomerGift>().Where(w => (idUsers.Contains(w.USERID) && typeUser != 1 && typeUser != 2) || typeUser == 1 || typeUser == 2).ToList();
                    if (!string.IsNullOrEmpty(phanhe))
                    {
                        list = list.Where(p => p.PhanHe == phanhe).ToList();
                    }

                    if (!string.IsNullOrEmpty(acctno))
                    {
                        list = list.Where(p => p.Acctno == acctno).ToList();
                    }

                    if (!string.IsNullOrEmpty(promotionId))
                    {
                        list = list.Where(p => p.Promotion.Id == new Guid(promotionId)).ToList();
                    }
                    var cus = list.GroupBy(p => new
                    {
                        PromotionId = p.Promotion.Id,
                        p.ParentId,
                        p.CusId,
                        p.PhanHe,
                        p.Acctno,
                        p.CusName,
                        p.TERM,
                        p.TERMCD,
                        p.BALANCE,
                        p.CCYCD,
                        p.FRDATE,
                        p.NgayDuyet,
                        p.NguoiDuyet,
                        p.Status,
                        p.CREATEDBy,
                        p.CREATEDDATE
                    }).Select(p => new
                    {
                        Id = p.Key.ParentId,
                        p.Key.CusId,
                        p.Key.PhanHe,
                        p.Key.Acctno,
                        p.Key.PromotionId,
                        PromotionName = ContextProvider.GetPromotionName(lstPromotion, p.Key.PromotionId),
                        NumGift       = p.Sum(t => t.NumGift),
                        p.Key.CusName,
                        p.Key.TERM,
                        p.Key.TERMCD,
                        p.Key.BALANCE,
                        p.Key.CCYCD,
                        FRDATE     = ContextProvider.GetConvertDatetime(p.Key.FRDATE),
                        NgayDuyet  = ContextProvider.GetConvertDatetime(p.Key.NgayDuyet),
                        NguoiDuyet = ContextProvider.GetFullName(lstUser, p.Key.NguoiDuyet),
                        p.Key.Status,
                        CREATEDBy   = ContextProvider.GetFullName(lstUser, p.Key.CREATEDBy),
                        CREATEDDATE = ContextProvider.GetConvertDatetime(p.Key.CREATEDDATE),
                    }).ToList();

                    result.Cus       = cus.Skip((pageNo - 1) * pageSize).Take(pageSize).ToList();
                    var total        = cus.Count();
                    result.TotalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
                });
            }
            catch (Exception)
            {
                throw;
            }
            return(result);
        }