Esempio n. 1
0
        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));
            }
        }