public async Task <List <CheckListItemSelectionDto> > GetSelectionAsync(GetSelectionInput input) { var selections = await _selectionRepository.GetAll() .Where(i => i.OwnerType == input.OwnerType && i.OwnerId == input.OwnerId && i.CheckListItem.CheckList.Id == input.Id) .ToListAsync(); var lastSelections = selections.GroupBy(i => i.CheckListItem, (checkListItem, items) => new { CheckListItem = checkListItem, LastSelection = items.OrderByDescending(s => s.CreationTime).FirstOrDefault() }) .Select(g => g.LastSelection) .ToList(); var result = lastSelections.Select(i => new CheckListItemSelectionDto { CheckListItemId = i.CheckListItem.Id, Comments = i.Comments, Selection = (int?)i.Selection }).ToList(); return(result); }
public async Task <IHttpActionResult> GetSelection([FromBody] GetSelectionInput json) { json.FirstIndex = json.FirstIndex - 1; try { if (json.SelectionId == "province") // استان { var count = await _provinceService.GetProvinceCountAsync(); if (json.FirstIndex > count) { return(Ok(new { items = new List <ButtonSimpleModel>() })); } if (json.LastIndex > count) { json.LastIndex = count; } var provinceList = await _provinceService.GetProvinceListAsync(json.FirstIndex, json.LastIndex); var buttonSimpleList = new List <ButtonSimpleModel>(); foreach (var province in provinceList) { buttonSimpleList.Add(new ButtonSimpleModel { Type = ButtonSimpleTypeEnum.TextOnly, Text = province.Name, ImageUrl = null }); } return(Ok(new { items = buttonSimpleList })); } if (json.SelectionId == "city") // شهر { var account = await _userInfoService.GetUserInfo(json.ChatId); var count = await _provinceService.GetCityCountAsync(account.ProvinceId.Value); if (json.FirstIndex > count) { return(Ok(new { items = new List <ButtonSimpleModel>() })); } if (json.LastIndex > count) { json.LastIndex = count; } var cityList = await _provinceService.GetCityListAsync(account.ProvinceId.Value, json.FirstIndex, json.LastIndex); var buttonSimpleList = new List <ButtonSimpleModel>(); foreach (var city in cityList) { buttonSimpleList.Add(new ButtonSimpleModel { Type = ButtonSimpleTypeEnum.TextOnly, Text = city.Name, ImageUrl = null }); } return(Ok(new { items = buttonSimpleList })); } if (json.SelectionId == "bank") { var count = await _bankService.GetBankCount(); if (json.FirstIndex > count) { return(Ok(new { items = new List <ButtonSimpleModel>() })); } if (json.LastIndex > count) { json.LastIndex = count; } var bankList = await _bankService.GetBankList(json.FirstIndex, json.LastIndex); var buttonSimpleList = new List <ButtonSimpleModel>(); foreach (var bank in bankList) { buttonSimpleList.Add(new ButtonSimpleModel { Type = ButtonSimpleTypeEnum.TextOnly, Text = bank.Name, ImageUrl = null }); } return(Ok(new { items = buttonSimpleList })); } return(CustomResult()); } catch (Exception exception) { return(CustomError(exception)); } }
public async Task <IHttpActionResult> GetSelection([FromBody] GetSelectionInput json) { json.FirstIndex = json.FirstIndex - 1; try { if (json.SelectionId == "provinces") // استان { var count = await _provinceService.GetProvinceCountAsync(); if (json.FirstIndex > count) { return(Ok(new { items = new List <ButtonSimpleModel>() })); } if (json.LastIndex > count) { json.LastIndex = count; } var provinceList = await _provinceService.GetProvinceListAsync(json.FirstIndex, json.LastIndex); var buttonSimpleList = new List <ButtonSimpleModel>(); foreach (var province in provinceList) { buttonSimpleList.Add(new ButtonSimpleModel { Type = ButtonSimpleTypeEnum.TextOnly, Text = province.Title, ImageUrl = null }); } return(Ok(new { items = buttonSimpleList })); } if (json.SelectionId == "axes") { var count = await _festivalService.GetFestivalAxesListCountAsync(); if (json.FirstIndex > count) { return(Ok(new { items = new List <ButtonSimpleModel>() })); } if (json.LastIndex > count) { json.LastIndex = count; } var list = await _festivalService.GetFestivalAxesListAsync(json.FirstIndex, json.LastIndex); var buttonSimpleList = new List <ButtonSimpleModel>(); foreach (var item in list) { buttonSimpleList.Add(new ButtonSimpleModel { Type = ButtonSimpleTypeEnum.TextOnly, Text = $"{item.Title}", ImageUrl = null }); } return(Ok(new { items = buttonSimpleList })); } if (json.SelectionId == "fields") { var info = await _groupService.GetGroupInfo(json.ChatId); var count = await _festivalService.GetFestivalFieldsListCountAsync(info.FestivalAxId.Value); if (json.FirstIndex > count) { return(Ok(new { items = new List <ButtonSimpleModel>() })); } if (json.LastIndex > count) { json.LastIndex = count; } var list = await _festivalService.GetFestivalFieldsListAsync(info.FestivalAxId.Value, json.FirstIndex, json.LastIndex); var buttonSimpleList = new List <ButtonSimpleModel>(); foreach (var item in list) { buttonSimpleList.Add(new ButtonSimpleModel { Type = ButtonSimpleTypeEnum.TextOnly, Text = $"{item.Title}", ImageUrl = null }); } return(Ok(new { items = buttonSimpleList })); } if (json.SelectionId == "majors") { var info = await _groupService.GetGroupInfo(json.ChatId); var count = await _festivalService.GetFestivalMajorsListCountAsync(info.FestivalFieldId.Value); if (json.FirstIndex > count) { return(Ok(new { items = new List <ButtonSimpleModel>() })); } if (json.LastIndex > count) { json.LastIndex = count; } var list = await _festivalService.GetFestivalMajorsListAsync(info.FestivalFieldId.Value, json.FirstIndex, json.LastIndex); var buttonSimpleList = new List <ButtonSimpleModel>(); foreach (var item in list) { buttonSimpleList.Add(new ButtonSimpleModel { Type = ButtonSimpleTypeEnum.TextOnly, Text = $"{item.Title}", ImageUrl = null }); } return(Ok(new { items = buttonSimpleList })); } return(CustomResult()); } catch (Exception exception) { return(CustomError(exception)); } }