public IList <TemplateViewModel> ListAll(TemplateSearchModel model) { try { IQueryable <TemplateViewModel> list; if (string.IsNullOrEmpty(model.Skill)) { list = from template in dc.Template select new TemplateViewModel { Content = template.Content, Created = template.Created, Duration = template.Duration, ID = template.ID, PassScore = template.PassScore, Skill = template.Skill, QuestionQuantity = dc.Question.Where(c => c.TemplateId == template.ID).Count() }; } else { list = from template in dc.Template where template.Skill.ToLower().Contains(model.Skill.ToLower()) select new TemplateViewModel { Content = template.Content, Created = template.Created, Duration = template.Duration, ID = template.ID, PassScore = template.PassScore, Skill = template.Skill, QuestionQuantity = dc.Question.Where(c => c.TemplateId == template.ID).Count() }; } var result = list.ToList(); foreach (var item in result) { var done = (from res in dc.Result where res.TemplateId == item.ID select res).ToList(); item.QuantityDone = done.Count; item.MaxScore = done.Select(c => c.Score).Max(); item.MinScore = done.Select(c => c.Score).Min(); } //model.Paging.RowsCount = list.Count(); return(result);// list.Skip(model.Paging.PageSize * (model.Paging.CurrentPage - 1)).Take(model.Paging.PageSize).ToList(); } catch (System.Exception ex) { throw ex; } }
public ApiResult ListAll(TemplateSearchModel model) { try { var result = _TemplateBLService.ListAll(model); return(new ApiResult { Status = HttpStatus.OK, Data = new { list = result, model.Paging } }); } catch (Exception ex) { return(new ApiResult() { Status = HttpStatus.InteralError, Message = ex.Message }); } }
public IList <TemplateViewModel> ListAll(TemplateSearchModel model) { return(_TemplateService.ListAll(model)); }