コード例 #1
0
        public async Task <IActionResult> PutPlantDetail(int id, PlantDetail plantDetail)
        {
            if (id != plantDetail.PMid)
            {
                return(BadRequest());
            }

            _context.Entry(plantDetail).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlantDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
ファイル: FileOperations.cs プロジェクト: Esstonian/CSTest
        public void parseXml(Stream stream)
        {
            DateTime now = DateTime.Now;

            houses = new List <HouseName>();
            plants = new List <PlantName>();
            dates  = new Dictionary <int, DateTemp>();

            stream.Position = 0;
            XDocument xml = XDocument.Load(stream);

            foreach (XElement el in xml.Root.Element("houses").Elements("house"))
            {
                var house = new HouseName {
                    name = el.Attribute("Name").Value
                };
                houses.Add(house);
                foreach (XElement element in el.Elements())
                {
                    DateTemp dateTemp = new DateTemp {
                        dateTime    = getDate(element),
                        temperature = getDouble(element, "Weather")
                    };
                    TimeSpan span = (dateTemp.dateTime - DateTemp.zeroCountDateTime);
                    dateTemp.daysNumber = span.Days;
                    HouseDetail houseDetail = new HouseDetail {
                        localDateTemp    = now,
                        userName         = getUserName(),
                        daysNumber       = dateTemp.daysNumber,
                        consumptionHouse = getDouble(element, "Consumption")
                    };
                    if (!dates.ContainsKey(span.Days))
                    {
                        dates.Add(span.Days, dateTemp);
                    }
                    house.listHouseDetails.Add(houseDetail);
                }
            }

            foreach (XElement el in xml.Root.Elements("plants").Elements())
            {
                PlantName plant = new PlantName {
                    name = el.Attribute("Name").Value
                };
                plants.Add(plant);
                foreach (XElement element in el.Elements())
                {
                    TimeSpan    span        = getDate(element) - DateTemp.zeroCountDateTime;
                    PlantDetail plantDetail = new PlantDetail {
                        localDateTemp    = now,
                        userName         = getUserName(),
                        daysNumber       = span.Days,
                        price            = getDouble(element, "Price"),
                        consumptionPlant = getDouble(element, "Consumption")
                    };
                    plant.listPlantDetails.Add(plantDetail);
                }
            }
            saveToDb();
        }
コード例 #3
0
        public async Task <ActionResult <PlantDetail> > PostPlantDetail(PlantDetail plantDetail)
        {
            _context.PlantDetails.Add(plantDetail);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPlantDetail", new { id = plantDetail.PMid }, plantDetail));
        }
コード例 #4
0
    void Start()
    {
        int num = 0;
        //high = 0.872 width = 1.144
        float xPlant = -4.3f;
        float yPlant = 0.3f;

        for (int y = 0; y < 4; y++)
        {
            for (int x = 0; x < 6; x++)
            {
                var Plant = Instantiate(plant, new Vector3(xPlant, yPlant, 0), Quaternion.identity);
                Plant.name = "nothing" + num.ToString();
                PlantDetail plantdetail = new PlantDetail();
                plantdetail.Name  = Plant.name;
                plantdetail.index = num;
                list.Add(plantdetail);
                xPlant += 1.3f;
                num    += 1;
            }
            xPlant  = -4.3f;
            yPlant -= 1f;
        }
        Sencestatus = "Farming";
    }
コード例 #5
0
        /// <summary>
        /// retrieve a plant using the repository
        /// </summary>
        /// <returns>plant</returns>
        private PlantDetail GetPlant(int id)
        {
            PlantDetail plant = null;

            FileIoStatus = FileIoMessage.None;

            try
            {
                using (PlantRepository pRepository = new PlantRepository())
                {
                    plant = pRepository.GetById(id);
                };

                if (plant != null)
                {
                    FileIoStatus = FileIoMessage.Complete;
                }
                else
                {
                    FileIoStatus = FileIoMessage.RecordNotFound;
                }
            }
            catch (Exception)
            {
                FileIoStatus = FileIoMessage.FileAccessError;
            }

            return(plant);
        }
コード例 #6
0
 private void ResetDetailedViewPlant()
 {
     _detailedViewPlant               = new PlantDetail();
     _detailedViewPlant.Name          = "";
     _detailedViewPlant.Description   = "";
     _detailedViewPlant.ImageFileName = "";
     _detailedViewPlant.ImageFilePath = "";
     OnPropertyChanged("DetailedViewPlant");
 }
コード例 #7
0
 private void UpdateDetailedViewPlantToSelected()
 {
     _detailedViewPlant               = new PlantDetail();
     _detailedViewPlant.Id            = _selectedPlant.Id;
     _detailedViewPlant.Name          = _selectedPlant.Name;
     _detailedViewPlant.Description   = _selectedPlant.Description;
     _detailedViewPlant.ImageFileName = _selectedPlant.ImageFileName;
     _detailedViewPlant.ImageFilePath = _selectedPlant.ImageFilePath;
     OnPropertyChanged("DetailedViewPlant");
 }
コード例 #8
0
 /// <summary>
 /// add a new plant
 /// </summary>
 /// <param name="plant">plant</param>
 public void Add(PlantDetail plants)
 {
     try
     {
         plants.Id = NextId();
         _plants.Add(plants);
         _dataService.WriteAll(_plants);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #9
0
        /// <summary>
        /// update a plant
        /// </summary>
        /// <param name="plant">plant</param>
        public void Update(PlantDetail plants)
        {
            try
            {
                _plants.Remove(_plants.FirstOrDefault(c => c.Id == plants.Id));
                _plants.Add(plants);

                _dataService.WriteAll(_plants);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #10
0
        public List <PlantDetail> Get()
        {
            List <PlantDetail> Plants = new List <PlantDetail>();

            foreach (var _plant in Enum.GetValues(typeof(Plants)))
            {
                PlantDetail plant = new PlantDetail();
                plant.PlantName   = _plant.ToString();
                plant.PlantId     = (int)_plant;
                plant.Status      = Status.NeedToWater.ToString();
                plant.WateredLast = null;
                Plants.Add(plant);
            }
            return(Plants);
        }
コード例 #11
0
        public static PlantDetail GetPlantDetail(Type plantType)
        {
            PlantDetail plantDetail = new PlantDetail();

            #region Trees

            if (plantType == typeof(LeafyBush))
            {
                plantDetail.Name = "a leafy bush";

                plantDetail.DisplayName    = "Leafy Bush";
                plantDetail.DisplayNameHue = 2499;

                plantDetail.Description = "a leafy and vibrant bush";

                plantDetail.IconItemID       = 13285;
                plantDetail.IconHue          = 0;
                plantDetail.IconOffsetX      = 48;
                plantDetail.IconOffsetY      = 21;
                plantDetail.GumpCollectionId = "";

                plantDetail.PlantGroup = PlantGroupType.Tree;
            }

            if (plantType == typeof(PointyBush))
            {
                plantDetail.Name = "a pointy bush";

                plantDetail.DisplayName    = "Pointy Bush";
                plantDetail.DisplayNameHue = 2499;

                plantDetail.Description = "a sharp and pointy bush";

                plantDetail.IconItemID       = 13279;
                plantDetail.IconHue          = 0;
                plantDetail.IconOffsetX      = 54;
                plantDetail.IconOffsetY      = -11;
                plantDetail.GumpCollectionId = "";

                plantDetail.PlantGroup = PlantGroupType.Tree;
            }

            #endregion

            return(plantDetail);
        }
コード例 #12
0
        /// <summary>
        /// add a new plant
        /// </summary>
        /// <param name="plant">plant to add</param>
        public void AddPlant(PlantDetail plant)
        {
            try
            {
                if (plant != null)
                {
                    using (PlantRepository pRepository = new PlantRepository())
                    {
                        pRepository.Add(plant);
                    };

                    FileIoStatus = FileIoMessage.Complete;
                }
            }
            catch (Exception)
            {
                FileIoStatus = FileIoMessage.FileAccessError;
            }
        }
コード例 #13
0
        private void OnSavePlant()
        {
            switch (_operationStatus)
            {
            case OperationStatus.ADD:
                if (_detailedViewPlant != null)
                {
                    // add plant to persistence
                    _pBusiness.AddPlant(_detailedViewPlant);

                    // add plant to list - update view
                    _plants.Add(DetailedViewPlant);
                }
                break;

            case OperationStatus.EDIT:
                PlantDetail plantToUpdate = _plants.FirstOrDefault(c => c.Id == SelectedPlant.Id);

                if (plantToUpdate != null)
                {
                    // update plant in persistence
                    _pBusiness.UpdatePlant(DetailedViewPlant);

                    // update plant in list - update view
                    _plants.Remove(plantToUpdate);
                    _plants.Add(DetailedViewPlant);
                }
                break;

            default:
                break;
            }

            ResetDetailedViewPlant();
            IsEditingAdding  = false;
            ShowAddButton    = true;
            _operationStatus = OperationStatus.NONE;
        }
コード例 #14
0
        public void UpdatePlant(PlantDetail updatedPlant)
        {
            try
            {
                if (GetPlant(updatedPlant.Id) != null)
                {
                    using (PlantRepository repo = new PlantRepository())
                    {
                        repo.Update(updatedPlant);
                    }

                    FileIoStatus = FileIoMessage.Complete;
                }
                else
                {
                    FileIoStatus = FileIoMessage.RecordNotFound;
                }
            }
            catch (Exception)
            {
                FileIoStatus = FileIoMessage.FileAccessError;
            }
        }