Exemple #1
0
        public async Task Load()
        {
            using (var client = new HttpClient())
            {
                URLBuilder url = new URLBuilder(_filter, controler);
                url.URL += "&ShowMyOffers=false";
                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 <SellOfferDto> result = JsonConvert.DeserializeObject <List <SellOfferDto> >(contents);
                Offers.Clear();
                foreach (SellOfferDto bo in result)
                {
                    SellOfferWrapper boffer = bo.createSellOffer();
                    Offers.Add(boffer);
                }
            }
        }
Exemple #2
0
 public SellTransactionViewModel(FilterViewModel filter, UserWrapper user, UserAuthenticationWrapper authenticationUser)
 {
     _authenticationUser = authenticationUser;
     _user         = user;
     _filter       = filter;
     Offers        = new BindableCollection <SellOfferWrapper>();
     SelectedOffer = new SellOfferWrapper(new sell_Offer());
     AcceptCommand = new AsyncRelayCommand(execute => Accept(), canExecute => { return(true); });
 }
Exemple #3
0
 public SellOfferViewModel(FilterViewModel filter, UserWrapper user, UserAuthenticationWrapper authenticationUser)
 {
     _authenticationUser = authenticationUser;
     _user         = user;
     _filter       = filter;
     _products     = new BindableCollection <ProductWrapper>();
     SellOffers    = new BindableCollection <SellOfferWrapper>();
     CreatedOffer  = SellOfferWrapper.CreateSellOffer(_user);
     UpdateCommand = new AsyncRelayCommand(execute => UpdateOffer(), canExecute => CanModifyOffer());
     DeleteCommand = new AsyncRelayCommand(execute => DeleteOffer(), canExecute => CanModifyOffer());
 }
Exemple #4
0
        SellOfferDto createOffer(SellOfferWrapper offer)
        {
            SellOfferDto wrap = new SellOfferDto();

            wrap.Id        = offer.Id;
            wrap.SellerId  = _authenticationUser.UserId;
            wrap.Price     = offer.Price;
            wrap.Amount    = offer.Amount;
            wrap.Name      = offer.Name;
            wrap.ProductId = offer.ProductId;
            return(wrap);
        }
        public SellOfferWrapper createSellOffer()
        {
            SellOfferWrapper offer = new SellOfferWrapper(new LGSA.Model.sell_Offer());

            offer.Id            = this.Id;
            offer.SellerId      = this.SellerId;
            offer.Price         = this.Price;
            offer.Amount        = this.Amount;
            offer.Name          = this.Name;
            offer.Seller        = new UserWrapper(new LGSA.Model.users());
            offer.Seller.Login  = this.User.UserName;
            offer.Seller.Rating = this.User.Rating;
            offer.ProductId     = this.ProductId;
            if (this.Product != null)
            {
                offer.Product = this.Product.createProduct();
            }
            return(offer);
        }
Exemple #6
0
        public async Task AddOffer()
        {
            if (CreatedOffer.Name == null || CreatedOffer.Product == null ||
                CreatedOffer.Amount <= 0 || CreatedOffer?.Price <= 0)
            {
                CreatedOffer = SellOfferWrapper.CreateSellOffer(_user);
                ErrorString  = (string)Application.Current.FindResource("InvalidSellOfferError");
                return;
            }
            using (var client = new HttpClient())
            {
                CreatedOffer.ProductId = CreatedOffer.Product.Id;
                FilterViewModel filter = new FilterViewModel(_filter);
                filter.Name = _createdOffer.Product.Name;
                URLBuilder url = new URLBuilder(filter, controler);
                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 <SellOfferDto> result = JsonConvert.DeserializeObject <List <SellOfferDto> >(contents);
                var totalAmount            = result.Sum(offer => offer.Amount);
                if (CreatedOffer.Amount + totalAmount > CreatedOffer.Product.Stock)
                {
                    CreatedOffer = SellOfferWrapper.CreateSellOffer(_user);
                    ErrorString  = (string)Application.Current.FindResource("StockError");
                    return;
                }
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                SellOfferDto content = createOffer(_createdOffer);

                var json = Newtonsoft.Json.JsonConvert.SerializeObject(content);
                url = new URLBuilder(controler);
                var request2 = new HttpRequestMessage()
                {
                    RequestUri = new Uri(url.URL),
                    Method     = HttpMethod.Post,
                    Content    = new StringContent(json,
                                                   Encoding.UTF8,
                                                   "application/json")
                };
                request2.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", _authenticationUser.UserId.ToString(), _authenticationUser.Password))));
                var response1 = await client.SendAsync(request2);

                if (response.IsSuccessStatusCode)
                {
                    await Load();

                    _createdOffer = SellOfferWrapper.CreateSellOffer(_user);
                }
                else
                {
                    ErrorString = (string)Application.Current.FindResource("InsertSellOfferError");
                    return;
                }
            }
            ErrorString = null;
        }