public string Export(LossSearchFilter filter) { Expression <Func <Loss, bool> > conditions = x => true; if (filter != null) { if (filter.UserId != null) { conditions = conditions.And(x => x.UserId == filter.UserId); } if (!string.IsNullOrWhiteSpace(filter.LossDateShFrom)) { var from = PersianDateTime.Parse(filter.LossDateShFrom).ToDateTime(); conditions = conditions.And(x => x.InsertDateMi >= from); } if (!string.IsNullOrWhiteSpace(filter.LossDateShFrom)) { var to = PersianDateTime.Parse(filter.LossDateShFrom).ToDateTime(); conditions = conditions.And(x => x.InsertDateMi <= to); } if (filter.LossType.IsNotNull()) { conditions = conditions.And(x => x.LossType == filter.LossType); } if (!string.IsNullOrWhiteSpace(filter.NationalCode)) { conditions = conditions.And(x => x.User.NationalCode == filter.NationalCode); } } var result = _LossRepo.Get(conditions, x => x.OrderByDescending(u => u.LossId), new List <Expression <Func <Loss, object> > > { i => i.User, i => i.LossAssets }); var ids = result.Where(x => x.RelativeId != null).Select(x => x.RelativeId).ToList(); var relatives = _appUow.RelativeRepo.Get(x => ids.Contains(x.RelativeId), o => o.OrderByDescending(x => x.RelativeId)); var sb = new StringBuilder(",User,Mobile Number,National Code,Patient Name,Cost Type,Cost,Date,Status,Description" + Environment.NewLine); int idx = 1; Relative relative = null; string relativeName = string.Empty; foreach (var loss in result) { if (loss.RelativeId != null) { relative = relatives.FirstOrDefault(x => x.RelativeId == loss.RelativeId); relativeName = relative == null ? ServiceMessage.OriginalInsured : relative.Fullname; } else { relativeName = ServiceMessage.OriginalInsured; } sb.Append($"{idx},{loss.User.Fullname},{loss.User.MobileNumber},{loss.User.NationalCode},{relativeName},{loss.LossType.GetDescription()},{loss.Cost.ToString("N0")},{loss.LossDateSh},{loss.Status.GetDescription()},{loss.Description}" + Environment.NewLine); idx++; } return(sb.ToString()); }
public virtual ActionResult Manage(LossSearchFilter filter) { ViewBag.Types = GetTypes(); filter.UserId = User.GetUserId(); if (!Request.IsAjaxRequest()) { return(View(_LossSrv.Get(filter))); } else { return(PartialView("Partials/_List", _LossSrv.Get(filter))); } }
public virtual ActionResult Manage(LossSearchFilter filter) { ViewBag.WithoutAddButton = true; ViewBag.ExcelExport = true; ViewBag.Types = GetTypes(); if (!Request.IsAjaxRequest()) { return(View(_LossSrv.Get(filter))); } else { return(PartialView("Partials/_List", _LossSrv.Get(filter))); } }
public PagingListDetails <Loss> Get(LossSearchFilter filter) { Expression <Func <Loss, bool> > conditions = x => true; if (filter != null) { if (filter.UserId != null) { conditions = conditions.And(x => x.UserId == filter.UserId); } if (!string.IsNullOrWhiteSpace(filter.LossDateShFrom)) { var from = PersianDateTime.Parse(filter.LossDateShFrom).ToDateTime(); conditions = conditions.And(x => x.InsertDateMi >= from); } if (!string.IsNullOrWhiteSpace(filter.LossDateShFrom)) { var to = PersianDateTime.Parse(filter.LossDateShFrom).ToDateTime(); conditions = conditions.And(x => x.InsertDateMi <= to); } if (filter.LossType.IsNotNull()) { conditions = conditions.And(x => x.LossType == filter.LossType); } if (!string.IsNullOrWhiteSpace(filter.NationalCode)) { conditions = conditions.And(x => x.User.NationalCode == filter.NationalCode); } } var result = _LossRepo.Get(conditions, filter, x => x.OrderByDescending(u => u.LossId), new List <Expression <Func <Loss, object> > > { i => i.User, i => i.LossAssets }); var ids = result.Items.Where(x => x.RelativeId != null).Select(x => x.RelativeId).ToList(); var relatives = _appUow.RelativeRepo.Get(x => ids.Contains(x.RelativeId), o => o.OrderByDescending(x => x.RelativeId)); foreach (var loss in result.Items.Where(x => x.RelativeId != null)) { loss.Relative = relatives.FirstOrDefault(x => x.RelativeId == loss.RelativeId); } return(result); }
public virtual JsonResult Excel(LossSearchFilter filter) => Json(_LossSrv.Export(filter));