コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,NumberOfFrames,Temperament,Brood,Size,Species,Mites,HiveType,Propolis,HiveImageUrl,QueenCells,HiveStrength,SwarmPotential,HiveLat,HiveLon,PercentOfHiveBrood,PercentOfHiveEmpty,PercentOfHiveHoney,PercentOfHiveUnBrood,KeeperModelId")] HiveModel hiveModel)
        {
            if (id != hiveModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hiveModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HiveModelExists(hiveModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KeeperModelId"] = new SelectList(_context.Keepers, "Id", "Id", hiveModel.KeeperModelId);
            return(View(hiveModel));
        }
コード例 #2
0
        public static string SwarmCalc(HiveModel hiveModel)
        {
            int    valueSwarm  = PopChecker(hiveModel) + BroodChecker(hiveModel) + QueenCellChecker(hiveModel);
            string valueString = StringValue(valueSwarm);

            return(valueString);
        }
コード例 #3
0
 static int PopChecker(HiveModel hiveModel)
 {
     if (hiveModel.Size == "High")
     {
         value += 2;
         return(value);
     }
     else if (hiveModel.Size == "AboveAverage")
     {
         value += 1;
         return(value);
     }
     else if (hiveModel.Size == "Average")
     {
         return(value);
     }
     else if (hiveModel.Size == "Low")
     {
         value -= 1;
         return(value);
     }
     else if (hiveModel.Size == "VeryLow")
     {
         value -= 2;
         return(value);
     }
     else
     {
         return(value);
     }
 }
コード例 #4
0
        static int MiteChecker(HiveModel hiveModel)
        {
            DateTime currentMonth;

            currentMonth = DateTime.Now;
            int month = currentMonth.Month;

            if (month >= 10)
            {
                return(value);
            }
            else if (month >= 6 && month <= 9 && hiveModel.Mites >= 6)
            {
                value -= 2;
                return(value);
            }
            else if (month >= 3 && month <= 6 && hiveModel.Mites >= 3)
            {
                value -= 2;
                return(value);
            }
            else
            {
                value += 3;
                return(value);
            }
        }
コード例 #5
0
        public static string StrengthCalc(HiveModel hiveModel)
        {
            int valueStrength = FrameChecker(hiveModel) + BroodPatternChecker(hiveModel) + MiteChecker(hiveModel);
            var valueString   = GetValueString(valueStrength);

            return(valueString);
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,NumberOfFrames,Temperament,Brood,BroodPattern,Size,Species,Mites,HiveType,Propolis,HiveImageUrl,QueenCells,HiveStrength,SwarmPotential,HiveLat,HiveLon,PercentOfHiveBrood,PercentOfHiveEmpty,PercentOfHiveHoney,PercentOfHiveUnBrood,KeeperModelId")] HiveModel hiveModel)
        {
            if (ModelState.IsValid)
            {
                hiveModel.HiveStrength   = Strength.StrengthCalc(hiveModel);
                hiveModel.SwarmPotential = SwarmRisk.SwarmCalc(hiveModel);
                _context.Add(hiveModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KeeperModelId"] = new SelectList(_context.Keepers, "Id", "Id", hiveModel.KeeperModelId);
            return(View(hiveModel));
        }
コード例 #7
0
        public async Task <IHttpActionResult> Put(int hiveId, HiveModel hiveModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Hive Model is not valid"));
            }

            try
            {
                using (var context = new BeeAppContext())
                {
                    var hive = await context.Beekeepers
                               .Where(x => x.ApplicationUserId == _applicationUserId)
                               .Include(x => x.Apiaries)
                               .SelectMany(x => x.Apiaries)
                               .Include(x => x.Hives)
                               .SelectMany(x => x.Hives)
                               .Where(x => x.Id == hiveId)
                               .FirstOrDefaultAsync();

                    if (hive != null)
                    {
                        hive.Name         = hiveModel.Name;
                        hive.Date         = hiveModel.Date;
                        hive.Status       = hiveModel.Status;
                        hive.Type         = hiveModel.Type;
                        hive.Note         = hiveModel.Note;
                        hive.Family       = hiveModel.Family;
                        hive.FamilyOrigin = hiveModel.FamilyOrigin;

                        // Save
                        context.SaveChanges();

                        // Return
                        return(StatusCode(HttpStatusCode.NoContent));
                    }

                    // Return
                    return(BadRequest("Hive could not be found"));
                }
            }
            catch (Exception ex)
            {
                // Return
                return(BadRequest(ex.Message));
            }
        }
コード例 #8
0
 static int BroodPatternChecker(HiveModel hiveModel)
 {
     if (hiveModel.BroodPattern == "Solid")
     {
         value += 2;
         return(value);
     }
     else if (hiveModel.BroodPattern == "Spotty")
     {
         value -= 2;
         return(value);
     }
     else
     {
         value -= 2;
         return(value);
     }
 }
コード例 #9
0
        public IHttpActionResult Post(int apiaryId, HiveModel hiveModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Hive Model is not valid"));
            }

            try
            {
                using (var context = new BeeAppContext())
                {
                    if (!EnsureCreatingInOwnApiary(context, apiaryId))
                    {
                        return(BadRequest("The apiary could not be found."));
                    }

                    context.Hives.Add(new Hive
                    {
                        Name         = hiveModel.Name,
                        Date         = hiveModel.Date,
                        Status       = hiveModel.Status,
                        Type         = hiveModel.Type,
                        Note         = hiveModel.Note,
                        Family       = hiveModel.Family,
                        FamilyOrigin = hiveModel.FamilyOrigin,
                        ApiaryId     = apiaryId
                    });

                    // Save
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            // Return
            return(Ok(hiveModel));
        }
コード例 #10
0
 static int FrameChecker(HiveModel hiveModel)
 {
     if (hiveModel.NumberOfFrames <= 4)
     {
         value -= 2;
         return(value);
     }
     else if (hiveModel.NumberOfFrames >= 10 && hiveModel.NumberOfFrames <= 15)
     {
         value += 2;
         return(value);
     }
     else if (hiveModel.NumberOfFrames >= 5 && hiveModel.NumberOfFrames < 10)
     {
         value += 1;
         return(value);
     }
     else
     {
         value += 5;
         return(value);
     }
 }
コード例 #11
0
 static int BroodChecker(HiveModel hiveModel)
 {
     if (hiveModel.NumberOfFrames <= 20 && hiveModel.NumberOfFrames >= 16 && hiveModel.Brood > 4)
     {
         value += 2;
         return(value);
     }
     else if (hiveModel.NumberOfFrames <= 20 && hiveModel.NumberOfFrames >= 16 && hiveModel.Brood < 5 && hiveModel.Brood > 1)
     {
         value += 1;
         return(value);
     }
     else if (hiveModel.NumberOfFrames <= 20 && hiveModel.NumberOfFrames >= 16 && hiveModel.Brood <= 1)
     {
         value -= 3;
         return(value);
     }
     else if (hiveModel.NumberOfFrames <= 16 && hiveModel.Brood > 2)
     {
         value += 2;
         return(value);
     }
     else if (hiveModel.NumberOfFrames <= 16 && hiveModel.Brood == 2)
     {
         value += 1;
         return(value);
     }
     else if (hiveModel.NumberOfFrames <= 16 && hiveModel.Brood < 2)
     {
         value -= 3;
         return(value);
     }
     else
     {
         return(value);
     }
 }
コード例 #12
0
        static int QueenCellChecker(HiveModel hiveModel)
        {
            DateTime currentMonth;

            currentMonth = DateTime.Now;
            int month = currentMonth.Month;
            int march = 3;
            int april = 4;
            int may   = 5;

            if (hiveModel.NumberOfFrames <= 20 && hiveModel.NumberOfFrames >= 16 && hiveModel.QueenCells > 5 && month == march || month == april || month == may)
            {
                value += 3;
                return(value);
            }
            else if (hiveModel.NumberOfFrames <= 20 && hiveModel.NumberOfFrames >= 16 && hiveModel.QueenCells <= 5 && hiveModel.QueenCells > 1 && month == march || month == april || month == may)
            {
                value += 1;
                return(value);
            }
            else if (hiveModel.NumberOfFrames <= 16 && hiveModel.QueenCells > 3 && month == march || month == april || month == may)
            {
                value += 2;
                return(value);
            }
            else if (hiveModel.NumberOfFrames <= 16 && hiveModel.QueenCells < 3 && month == march || month == april || month == may)
            {
                value += 1;
                return(value);
            }
            else
            {
                value -= 2;
                return(value);
            }
        }