public void Post([FromBody] List <RequestJSONModel> res)
        {
            //sent data to list
            List <RequestJSONModel> receivedItems = res.ToList();

            //iteration on the list of objects
            for (int i = 0; i < receivedItems.Count(); i++)
            {
                try
                {
                    //parse
                    RequestJSONModel dataItem = new RequestJSONModel
                    {
                        Index  = receivedItems[i].Index,
                        Name   = receivedItems[i].Name,
                        Visits = receivedItems[i].Visits,
                        Date   = receivedItems[i].Date
                    };
                    //calling repo
                    _repository.AddItem(dataItem);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }
        }
        public void AddItemTest()
        {
            _dataRepository.AddItem(new Item()
            {
                Store = _dataRepository.GetStoreById(1), StoreId = 1, Name = "Cake Mix", Price = 3.57M, Allergens = "Gluten", Aisle = "3", Section = "cakemix", InStock = true, StockAmount = 50
            });

            Assert.AreEqual(_dataRepository.GetItem(60).Name, "Cake Mix");
        }
Esempio n. 3
0
        public async Task <IActionResult> Post()
        {
            _log.Called();

            string             json    = "";
            List <PersonModel> persons = new List <PersonModel>();

            byte[] received = new byte[4096];

            using (var ms = new MemoryStream(2048))
            {
                try
                {
                    await Request.Body.CopyToAsync(ms);

                    received = ms.ToArray();
                }
                catch (Exception e)
                {
                    _log.Error("Could receive data. " + e.Message);

                    return(StatusCode((int)HttpStatusCode.BadRequest));
                }
            }

            json = _serializationService.UnzipData(received);

            if (!string.IsNullOrEmpty(json))
            {
                persons = _serializationService.DeserializeDataFromJson(json);
            }
            else
            {
                _log.Error("Could not decompress data.");

                return(StatusCode((int)HttpStatusCode.BadRequest));
            }

            if (persons.Count > 0)
            {
                foreach (var person in persons)
                {
                    _repository.AddItem(person);
                }
            }
            else
            {
                _log.Error("Data collection empty.");

                return(StatusCode((int)HttpStatusCode.BadRequest));
            }

            return(StatusCode((int)HttpStatusCode.OK));
        }
Esempio n. 4
0
        public ActionResult Create(Item item)
        {
            _dataRepository.AddItem(item);

            return(View());
        }