Esempio n. 1
0
        public async Task <IActionResult> Download(int id)
        {
            var bll_g  = groupBusiness;
            var bll_gm = groupMemberBusiness;
            var user   = HttpContext.Items["EndUser"] as EF.EndUser;

            if (!await bll_g.IsSelectedIdsOk(new int[] { id }, user))
            {
                return(Unauthorized());
            }

            var res = from r in await bll_gm.Members(new EF.Member(), id).ToListAsync()
                      join genders in (await lookUpBusiness.GetByGroup("Gender")).Select(x => new { Label = x.Name, Value = int.Parse(x.Value) }) on r.Gender equals genders.Value into e
                      from e1 in e.DefaultIfEmpty()
                      join civilStatuses in (await lookUpBusiness.GetByGroup("Civil Status")).Select(x => new { Label = x.Name, Value = int.Parse(x.Value) }) on r.CivilStatus equals civilStatuses.Value into f
                      from f1 in f.DefaultIfEmpty()
                      join m in memberBusiness.Find(new EF.Member {
                CommunityId = user.Member.CommunityId
            }) on r.InvitedBy equals m.Id into g
                      from m1 in g.DefaultIfEmpty()
                      select new
            {
                r.Id,
                r.Name,
                r.NickName,
                r.Address,
                r.Mobile,
                r.Email,
                r.BirthDate,
                r.Remarks,
                r.CivilStatus,
                r.Gender,
                InvitedByMemberName = m1 == null ? "" : m1.Name,
                r.IsActive
            };

            var bytes = Encoding.ASCII.GetBytes(res.ToList().ExportToCsv().ToString());

            var result = new FileContentResult(bytes, "text/csv");

            result.FileDownloadName = "my-csv-file.csv";
            return(result);
        }
Esempio n. 2
0
 public Member Find(Func <Member, bool> predicate) => _member.Find(predicate);