Example #1
0
        public async Task <Roscon> CreateRosconAsync(Roscon roscon)
        {
            try
            {
                string json    = JsonConvert.SerializeObject(roscon, Formatting.Indented);
                var    content = new StringContent(json.ToLower(), Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PostAsync($"{rosconUrl}?token={Constants.Token}", content);

                if (response.IsSuccessStatusCode)
                {
                    var resp = await response.Content.ReadAsStringAsync();

                    Roscon rosconFromDb = JsonConvert.DeserializeObject <Roscon>(resp);

                    return(rosconFromDb);
                }

                return(null);
            }
            catch (Exception e)
            {
                Log.Warning("CreateRosconAsync error", $"Error -> {e.Message}");
                throw e;
            }
        }
Example #2
0
        private void SetRosconesAndTypes(List<Roscon> roscones, List<RosconType> rosconTypes, StackLayout panel)
        {
            foreach (var rosconType in rosconTypes)
            {
                Label rosconTypeLabel = new Label()
                {
                    Text = rosconType.Tipo
                };
                Roscon roscon = roscones.Find(x => x.Tipo_Roscon == rosconType.Id);
                Entry rosconInput = new Entry()
                {
                    Text = roscon.Cantidad.ToString(),
                    Keyboard = Keyboard.Numeric
                };
                Button addAmount = new Button { Text = "+", VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Center };
                Button subtractAmount = new Button { Text = "-", VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Center };
                Button editAmount = new Button { Text = "edit", VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Center };
                StackLayout buttonsPanel = new StackLayout
                {
                    Margin = new Thickness(5),
                    Orientation = StackOrientation.Horizontal,
                    HorizontalOptions = LayoutOptions.Center,
                    Children = { addAmount, subtractAmount, editAmount }
                };

                if (roscon == null)
                    // TODO -> Anno passing as argument
                    roscon = new Roscon { Id = null, Cantidad = 0, Tipo_Roscon = rosconType.Id, Anno = DateTime.Now.Year };

                inputs.Add(new EntryRoscon { Entry = rosconInput, Roscon = roscon, AddButton = addAmount, SubtractButton = subtractAmount, EditButton = editAmount, Amount = 0 });
                totalLabel.Text = (int.Parse(totalLabel.Text) + roscon.Cantidad).ToString();

                addAmount.Clicked += AddAmountEvent;
                subtractAmount.Clicked += SubtractAmountEvent;
                editAmount.Clicked += EditAmountEvent;

                rosconInput.TextChanged += UpdateAmountsEvent;

                panel.Children.Add(rosconTypeLabel);
                panel.Children.Add(rosconInput);
                panel.Children.Add(buttonsPanel);
            }
        }
Example #3
0
        public async Task <Roscon> UpdateRosconAsync(Roscon roscon)
        {
            try
            {
                string resp;
                string json    = JsonConvert.SerializeObject(roscon, Formatting.Indented);
                var    content = new StringContent(json.ToLower(), Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PutAsync($"{rosconUrl}{roscon.Id}/?token={Constants.Token}", content);

                response.EnsureSuccessStatusCode();

                resp = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <Roscon>(resp));
            }
            catch (Exception e)
            {
                Log.Warning("UpdateRosconAsync error", $"Error -> {e.Message}");
                throw e;
            }
        }
Example #4
0
 private async void UpdateRoscon(Roscon roscon)
 {
     rosconFromAPI = await rosconWrapper.UpdateRosconAsync(roscon);
 }
Example #5
0
 private async void CreateRoscon(Roscon roscon)
 {
     rosconFromAPI = await rosconWrapper.CreateRosconAsync(roscon);
     roscon.Id = rosconFromAPI.Id;
 }