Example #1
0
        public IActionResult PostHarvest([FromBody] dynamic harvest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //Harvest Data = harvest.First;

            var json        = JsonConvert.SerializeObject(harvest.First);
            var harvestData = JsonConvert.DeserializeObject <Harvest>(json);
            var json2       = JsonConvert.SerializeObject(harvest.Last);
            var landId      = JsonConvert.DeserializeObject <long>(json2);
            //var myCommandMessage = JsonConvert.DeserializeObject<Harvest>(harvest.First);
            long         id           = _datarepository.AddData(harvestData);
            Land_Harvest land_harvest = new Land_Harvest();
            var          lands        = _land.Get(landId);

            land_harvest.Lands    = lands;
            land_harvest.Harvests = harvestData;

            _land_Hatvest_datarepository.Add(land_harvest);



            return(CreatedAtAction("GetHarvest", new { id = harvestData.HarvestId }, harvestData));
        }
Example #2
0
        public async Task <DataResult <Dictionary <string, DataEntity> > > AddData(DataCommand command)
        {
            var data = DataEntity.Create(command);

            if (data.IsLeft)
            {
                if (await LeftDataIsValid(data.Id))
                {
                    return(DataResult <Dictionary <string, DataEntity> > .Fail("Error: Id already exist on left data."));
                }
            }
            else
            {
                if (await RightDataIsValid(data.Id))
                {
                    return(DataResult <Dictionary <string, DataEntity> > .Fail("Error: Id already exist on right data."));
                }
            }


            if (data.IsValid())
            {
                return(DataResult <Dictionary <string, DataEntity> > .Ok(await _dataRepository.AddData(data), "data successfully added."));
            }
            else
            {
                return(DataResult <Dictionary <string, DataEntity> > .Fail("Error: internal error."));
            }
        }
Example #3
0
        private bool AddDataFromFileIfExistsToDatabase(string fullFilePath) //return true if data added to database
        {
            var requests = FileData.GetRequestsFromFile(fullFilePath);

            if (requests != null && requests.Count != 0)
            {
                _dataRepository.AddData(fullFilePath, requests);
                return(true);
            }
            return(false);
        }