コード例 #1
0
        public async Task <int> PostCaterer(CatererDTO caterer)
        {
            var uri = _api.PostCaterer();

            var request = new HttpRequestMessage(HttpMethod.Post, uri);


            request.Content = new StringContent(System.Text.Json.JsonSerializer.Serialize(caterer));

            request.Content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");

            var client = _httpClientFactory;

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


            var response = await client.SendAsync(request);


            return(response.IsSuccessStatusCode ? JsonConvert.DeserializeObject <int>(await response.Content.ReadAsStringAsync()) : throw new Exception("Error cancelling order, try later."));


            // GoogleMapDTO locations = null;
            //if (response.IsSuccessStatusCode)
            //{
            //    var responseStream = await response.Content.ReadAsStringAsync();
            //    qRCodes = JsonConvert.DeserializeObject<QRDataCatering>(responseStream);
            //}

            //Checking the response is successful or not which is sent using HttpClient
            //TODO STO VRATITI AKO UPIT BUDE NEUSPIJESAN "Umjesto Exception"
            //return response.IsSuccessStatusCode ? JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()) : throw new Exception("Error cancelling order, try later.");
        }
コード例 #2
0
        public async Task <ActionResult> Create
            (CatererViewModel model)
        {
            if (ModelState.IsValid)
            {
                var newLocation = new GoogleMapDTO
                {
                    Address = model.Address,
                    Lat     = model.Lat,
                    Long    = model.Long
                };
                var userID =
                    _userManager.GetUserId(User);
                var newCaterer = new CatererDTO
                {
                    CatererID            = userID,
                    Address              = model.Address,
                    Lat                  = model.Lat,
                    Long                 = model.Long,
                    CateringFacilitiName = model.CateringFacilitiName,
                    CatererName          = model.CatererName
                };

                newLocation = await _GoogleMapSvc.Add(newLocation);

                var IDCateringFacility = await _CatererSvc.PostCaterer(newCaterer);


                List <Item> itemList = await _ExcelSvc.Get(model.FormDocument, IDCateringFacility);



                await _ItemSvc.PostItem(itemList);


                var QRImage = await _QRCodeSvc.GetQRImage(newLocation);



                return(File(QRImage.QRImageInBytes, System.Net.Mime.MediaTypeNames.Application.Octet, "MyQRCode.jpg"));
            }

            return(View("Index"));
        }