public async Task Load()
        {
            using (var client = new HttpClient())
            {
                URLBuilder url = new URLBuilder(_filter, controller);
                url.URL += "&ShowMyOffers=true";
                var request = new HttpRequestMessage()
                {
                    RequestUri = new Uri(url.URL),
                    Method     = HttpMethod.Get
                };
                request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", _authenticationUser.UserId.ToString(), _authenticationUser.Password))));
                var response = await client.SendAsync(request);

                var contents = await response.Content.ReadAsStringAsync();

                List <BuyOfferDto> result = JsonConvert.DeserializeObject <List <BuyOfferDto> >(contents);
                BuyOffers.Clear();
                foreach (BuyOfferDto bo in result)
                {
                    BuyOfferWrapper boffer = bo.createBuyOffer();
                    BuyOffers.Add(boffer);
                }
            }
        }
예제 #2
0
 public BuyTransactionViewModel(FilterViewModel filter, UserWrapper user, UserAuthenticationWrapper authenticationUser)
 {
     _authenticationUser = authenticationUser;
     _user         = user;
     _filter       = filter;
     Offers        = new BindableCollection <BuyOfferWrapper>();
     SelectedOffer = new BuyOfferWrapper(new buy_Offer());
     AcceptCommand = new AsyncRelayCommand(execute => Accept(), canExecute => { return(true); });
 }
        public BuyOfferViewModel(FilterViewModel filter, UserWrapper user, UserAuthenticationWrapper authenticationUser)
        {
            _authenticationUser = authenticationUser;
            _user        = user;
            BuyOffers    = new BindableCollection <BuyOfferWrapper>();
            CreatedOffer = BuyOfferWrapper.CreateEmptyBuyOffer(_user);

            _filter = filter;

            UpdateCommand = new AsyncRelayCommand(execute => UpdateOffer(), canExecute => CanModifyOffer());
            DeleteCommand = new AsyncRelayCommand(execute => DeleteOffer(), canExecute => CanModifyOffer());
        }
예제 #4
0
        BuyOfferDto createOffer(BuyOfferWrapper offer)
        {
            BuyOfferDto wrap = new BuyOfferDto();

            wrap.Id        = offer.Id;
            wrap.BuyerId   = _authenticationUser.UserId;
            wrap.Price     = offer.Price;
            wrap.Amount    = offer.Amount;
            wrap.Name      = offer.Name;
            wrap.ProductId = offer.ProductId;
            return(wrap);
        }
예제 #5
0
        public BuyOfferWrapper createBuyOffer()
        {
            BuyOfferWrapper wrap = new BuyOfferWrapper(new LGSA.Model.buy_Offer());

            wrap.Id           = this.Id;
            wrap.BuyerId      = this.BuyerId;
            wrap.Price        = this.Price;
            wrap.Amount       = this.Amount;
            wrap.Name         = this.Name;
            wrap.Buyer        = new UserWrapper(new LGSA.Model.users());
            wrap.Buyer.Login  = this.User.UserName;
            wrap.Buyer.Rating = this.User.Rating;
            wrap.ProductId    = this.ProductId;
            wrap.Product      = this.Product.createProduct();
            return(wrap);
        }
        public async Task AddOffer()
        {
            if (_createdOffer.Name == null || _createdOffer.Name == "" || _createdOffer.Product.Name == null || CreatedOffer.Amount <= 0 || CreatedOffer?.Price <= 0)
            {
                ErrorString = (string)Application.Current.FindResource("InvalidBuyOfferError");
                return;
            }
            CreatedOffer.Product.CheckForNull();
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                BuyOfferDto content = createOffer(_createdOffer);
                var         json    = Newtonsoft.Json.JsonConvert.SerializeObject(content);
                URLBuilder  url     = new URLBuilder(controller);
                var         request = new HttpRequestMessage()
                {
                    RequestUri = new Uri(url.URL),
                    Method     = HttpMethod.Post,
                    Content    = new StringContent(json,
                                                   Encoding.UTF8,
                                                   "application/json")
                };
                request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", _authenticationUser.UserId.ToString(), _authenticationUser.Password))));
                var response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    BuyOffers.Add(_createdOffer);
                    _createdOffer = BuyOfferWrapper.CreateEmptyBuyOffer(_user);
                }
                else
                {
                    ErrorString = (string)Application.Current.FindResource("InvalidBuyOfferError");
                    return;
                }
            }
            ErrorString = null;
        }