예제 #1
0
        public async Task <ChoiceGetData> PostAsync(ChoicePostData data)
        {
            using var connection = authService.Connection;

            var optionsArray = data.Options.Split(",").Select(o => o.Trim()).ToArray();

            if (optionsArray.Length < 2)
            {
                throw new Exception("At least 2 options are required.");
            }
            string optionsString = string.Join(",", optionsArray);

            var entity = new ChoiceEntity()
            {
                Name    = data.Name.Trim(),
                Options = optionsString,
                UserId  = authService.UserId
            };

            var context = new DatabaseContext(connection);
            await context.AddAsync(entity);

            await context.SaveChangesAsync();

            await connection.CloseAsync();

            return(CreateGetDataFromEntity(entity));
        }
예제 #2
0
        private async void CreateNewItemCommandExecute()
        {
            try
            {
                this.ShowNewItemPostIndicator(true);
                this.NewItemPostMessage = string.Empty;
                ChoicePostData body = new ChoicePostData()
                {
                    Name    = this.NewItemName,
                    Options = this.NewItemOptions
                };
                ChoiceGetData newItem = await this.client.ChoicePostAsync(body);

                this.Entries.Insert(0, this.container.Resolve <ChoiceEntryViewModel>().GetWithDataModel(newItem));
                this.NewItemName    = string.Empty;
                this.NewItemOptions = string.Empty;
            }
            catch (Exception e)
            {
                this.NewItemPostMessage = e.ToString();
            }
            finally
            {
                this.ShowNewItemPostIndicator(false);
            }
        }