public async Task DeleteOffer()
        {
            if (SelectedOffer != null)
            {
                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    BuyOfferDto content = createOffer(_selectedOffer);
                    var         json    = Newtonsoft.Json.JsonConvert.SerializeObject(content);
                    URLBuilder  url     = new URLBuilder(controller);
                    var         request = new HttpRequestMessage()
                    {
                        RequestUri = new Uri(url.URL),
                        Method     = HttpMethod.Delete,
                        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)
                    {
                        ErrorString = (string)Application.Current.FindResource("DeleteProductError");
                        return;
                    }
                    await Load();
                }
                ErrorString = null;
            }
        }
Esempio n. 2
0
        public async Task Accept()
        {
            string     rating = "";
            RateWindow win    = new RateWindow();

            win.ShowDialog();
            rating = win.Rating;

            BuyOfferDto bOffer = new BuyOfferDto();

            bOffer.Id        = 0;
            bOffer.BuyerId   = _authenticationUser.UserId;
            bOffer.Price     = (decimal?)SelectedOffer.Price;
            bOffer.Amount    = SelectedOffer.Amount;
            bOffer.Name      = "a";
            bOffer.ProductId = SelectedOffer.ProductId;
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                SellOfferDto   sellOffer   = createOffer(SelectedOffer);
                TransactionDto transaction = new TransactionDto();
                transaction.BuyOffer  = bOffer;
                transaction.SellOffer = sellOffer;
                if (rating == "")
                {
                    transaction.Rating = null;
                }
                else
                {
                    transaction.Rating = Convert.ToInt32(rating);
                }
                var json     = Newtonsoft.Json.JsonConvert.SerializeObject(transaction);
                var url      = new URLBuilder("/AcceptSellTransaction/");
                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 response = await client.SendAsync(request2);

                if (!response.IsSuccessStatusCode)
                {
                    ErrorString = (string)Application.Current.FindResource("TransactionError");
                    return;
                }
                Offers.Remove(SelectedOffer);
            }
        }
Esempio n. 3
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);
        }
        public async Task <IHttpActionResult> Post([FromBody] BuyOfferDto dto)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest("Invalid data"));
            }
            if (dto.BuyerId != (Thread.CurrentPrincipal as UserPrincipal).Id)
            {
                return(Unauthorized());
            }

            var offer  = _buyAssembler.DtoToEntity(dto);
            var result = await _service.Add(offer);

            if (result == ErrorValue.ServerError)
            {
                return(BadRequest("Transaction error"));
            }
            dto = _buyAssembler.EntityToDto(offer);
            return(Ok(dto));
        }
        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;
        }