Esempio n. 1
0
 public AddGroupBetPageViewModel(
     INavigationService navigationService,
     IApiService apiService,
     IFilesHelper filesHelper) : base(navigationService)
 {
     _navigationService = navigationService;
     _apiService        = apiService;
     _filesHelper       = filesHelper;
     Title       = "Nuevo Grupo de Apuestas";
     Image       = App.Current.Resources["UrlNoImage"].ToString();
     IsEnabled   = true;
     Tournaments = new ObservableCollection <TournamentResponse>();
     GroupBet    = new GroupBetRequest {
         CreationDate = DateTime.Today
     };
     LoadTournamentsAsync();
 }
Esempio n. 2
0
        public async Task <IActionResult> PostGroupBet([FromBody] GroupBetRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string picturePath = string.Empty;

            if (request.PictureArray != null && request.PictureArray.Length > 0)
            {
                picturePath = _imageHelper.UploadImage(request.PictureArray, "GroupBets");
            }



            var groupBet = new GroupBet
            {
                Admin = await _context.Players
                        .Include(u => u.User)
                        .FirstOrDefaultAsync(p => p.User.Email == request.PlayerEmail),
                CreationDate = request.CreationDate,
                Name         = request.Name,
                Tournament   = await _context.Tournaments.FindAsync(request.TournamentId),
                LogoPath     = picturePath,
            };

            var groupBetPlayer = new GroupBetPlayer
            {
                GroupBet = groupBet,
                Player   = await _context.Players
                           .Include(u => u.User)
                           .FirstOrDefaultAsync(p => p.User.Email == request.PlayerEmail),
                IsAccepted = true,
                IsBlocked  = false,
                Points     = 0
            };


            _context.GroupBets.Add(groupBet);
            _context.GroupBetPlayers.Add(groupBetPlayer);
            await _context.SaveChangesAsync();

            return(Ok(_converterHelper.ToGroupBetResponse(groupBet)));
            //return NoContent();
        }
Esempio n. 3
0
        public async Task <Response> AddGroupBetAsync(string urlBase, string servicePrefix, string controller, GroupBetRequest groupBetRequest, string tokenType, string accessToken)
        {
            try
            {
                string        request = JsonConvert.SerializeObject(groupBetRequest);
                StringContent content = new StringContent(request, Encoding.UTF8, "application/json");
                HttpClient    client  = new HttpClient
                {
                    BaseAddress = new Uri(urlBase)
                };

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tokenType, accessToken);
                string url = $"{servicePrefix}{controller}";
                HttpResponseMessage response = await client.PostAsync(url, content);

                string answer = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = answer
                    });
                }



                GroupBetResponse groupBet = JsonConvert.DeserializeObject <GroupBetResponse>(answer);

                if (response.IsSuccessStatusCode)
                {
                    return(new Response
                    {
                        IsSuccess = true,
                        Message = "Guardado con éxito!",
                        Result = groupBet,
                    });
                }


                Response obj = JsonConvert.DeserializeObject <Response>(answer);
                return(obj);
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = ex.Message
                });
            }
        }