public ActionResult New()
        {
            //            var viewModel = new ApiaryFormViewModel() //creating an empty ApiaryFormViewModel
            Apiary apiary = new Apiary()
            {
                ApiaryId = 0
            };

            return(View("ApiaryForm", apiary));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,Postcode")] Apiary apiary)
        {
            if (ModelState.IsValid)
            {
                _context.Add(apiary);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(apiary));
        }
 /// <summary>
 ///     Task to collect honey.
 /// </summary>
 /// <param name="apiary">Apiary</param>
 /// <param name="cancellationToken">CancellationToken</param>
 /// <returns></returns>
 internal static Task CollectHoneyTask(Apiary apiary, CancellationToken cancellationToken)
 {
     return(Task.Factory.StartNew(() =>
     {
         apiary.Hives.ForEach(hive =>
         {
             apiary.AmountOfCollectedHoney += hive.AmountOfHoney;
             hive.AmountOfHoney = 0;
         });
     }, cancellationToken));
 }
Beispiel #4
0
        public void NumberOfBeesTest()
        {
            var apiary = new Apiary(new List <Hive>
            {
                new Hive {
                    AmountOfWorkerBees = 10
                }
            });

            Assert.AreEqual(apiary.NumberOfBees, 11);
        }
        public Apiary CreateApiary(Apiary apiary)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            _context.Apiaries.Add(apiary);
            _context.SaveChanges();

            return(apiary);
        }
        private async void RemoveObject(object sender, EventArgs e)
        {
            Apiary removedApiary = (Apiary)(apiaryListView.SelectedItem);

            var question = await DisplayAlert(null, "Наистина ли искате да премахнете пчелин " + removedApiary.Name, "ДА", "НЕ");

            if (question.Equals("ДА"))
            {
                db.Delete(removedApiary);
                await DisplayAlert(null, "Пчелин " + removedApiary.Name + " е премахнат успешно", "ОК");
            }
        }
        public ApiaryDetailsViewModel(Apiary apiary)
        {
            _apiary          = apiary;
            LoadHivesCommand = new Command(async() => await ExecuteLoadHivesCommand());
            Hives            = new ObservableCollection <Hive>();

            MessagingCenter.Subscribe <HiveNewViewModel, Hive>(this, Messages.HIVE_ADDED, async(sender, obj) =>
            {
                var _item = obj as Hive;
                Hives.Add(_item);
                await DataStore.AddItemAsync(_item);
            });
        }
Beispiel #8
0
        public IActionResult Edit(int id, int aId)
        {
            ViewBag.Title = "Редактирование улья";
            IEnumerable <Apiary> ap = db.Apiaries.Where(i => i.Id == aId && i.User.Email == User.Identity.Name.ToString()).OrderBy(i => i.Id);
            Apiary app = ap.FirstOrDefault(i => i.Id == aId);

            if (app == null)
            {
                return(RedirectToAction("HiveView", "Apiary", new { id = aId }));
            }


            IEnumerable <Hive> api = _hive.Hives.Where(i => i.Apiary.Id == aId).OrderBy(i => i.Id);
            Hive hive = api.FirstOrDefault(i => i.Id == id);

            if (hive == null)
            {
                return(RedirectToAction("HiveView", "Apiary", new { id = aId }));
            }
            else
            {
                var hv = new HiveViewModel
                {
                    Id       = hive.Id,
                    Name     = hive.Name,
                    Desc     = hive.Desc,
                    Aid      = aId,
                    Force    = hive.Force,
                    Mass     = hive.Mass,
                    Frame    = hive.Frame,
                    Hframe   = hive.Hframe,
                    Wframe   = hive.Wframe,
                    Porod    = hive.Porod,
                    Heal     = hive.Heal,
                    Heal1    = hive.Heal1,
                    Heal2    = hive.Heal2,
                    Heal3    = hive.Heal3,
                    Heal4    = hive.Heal4,
                    Heal5    = hive.Heal5,
                    Heal6    = hive.Heal6,
                    Heal7    = hive.Heal7,
                    Heal8    = hive.Heal8,
                    Heal9    = hive.Heal9,
                    Matka    = hive.Matka,
                    DatePods = hive.DatePods,
                    Plod     = hive.Plod,
                    Prois    = hive.Prois
                };
                return(View(hv));
            }
        }
Beispiel #9
0
        public async Task <IActionResult> Add(ApiaryViewModel apiaryViewModel)
        {
            if (ModelState.IsValid)
            {
                IEnumerable <Apiary> api = _apiary.Apiaries.Where(i => i.User.Email.Equals(User.Identity.Name)).OrderBy(i => i.Id);

                Apiary apia = api.FirstOrDefault(i => i.Name == apiaryViewModel.Name);


                if (apia == null)
                {
                    string map = apiaryViewModel.Map;
                    if (map != null)
                    {
                        int found = apiaryViewModel.Map.IndexOf('"') + 1;
                        if (found != 0)
                        {
                            map   = apiaryViewModel.Map.Substring(found);
                            found = map.IndexOf('"');
                            if (found != -1)
                            {
                                map = map.Remove(found);
                            }
                        }
                    }



                    User courseToUpdate = await db.Users.FirstOrDefaultAsync(c => c.Email == User.Identity.Name.ToString());

                    db.Apiaries.Add(new Apiary {
                        Name = apiaryViewModel.Name, Map = map, Desc = apiaryViewModel.Desc, User = courseToUpdate
                    });
                    await db.SaveChangesAsync();

                    return(RedirectToAction("", "Apiary"));
                }
                else
                {
                    ModelState.AddModelError("", "Данное Название уже используется");
                    return(View(apiaryViewModel));
                }
            }
            else
            {
                return(View(apiaryViewModel));
            }
        }
Beispiel #10
0
        /// <summary>
        ///     Creates a new instance of <see cref="FunnyHoneyViewModelMock" />.
        /// </summary>
        public FunnyHoneyViewModelMock()
        {
            Apiary = new Apiary(new List <Hive>
            {
                new Hive
                {
                    AmountOfHoney      = 100,
                    AmountOfWorkerBees = 1000,
                    AmountOfGuards     = 120
                }
            });

            StartCommand   = new DelegateCommand(StartExecute, o => IsStarted);
            StopCommand    = new DelegateCommand(StopExecute, o => !IsStarted);
            CollectCommand = new DelegateCommand(CollectExecute, o => IsStarted);
        }
Beispiel #11
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Apiary = await _context.Apiaries
                     .Include(a => a.Beekeeper).FirstOrDefaultAsync(m => m.ApiaryId == id);

            if (Apiary == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Beispiel #12
0
        private async void Add(object sender, EventArgs e)
        {
            db.CreateTable <Beehive>();

            Beehive lastBeehive = db.Table <Beehive>().OrderByDescending(b => b.ID).FirstOrDefault();
            int     id;

            if (lastBeehive == null)
            {
                id = 1;
            }
            else
            {
                id = lastBeehive.ID++;
            }

            Beehive beehive = new Beehive()
            {
                ID          = id,
                Number      = _number.Text,
                Stores      = int.Parse(_stores.Text),
                Name        = _name.Text,
                TypeBeehive = _typeOfBeehive.SelectedItem.ToString(),
                TypeBees    = _typeOfBee.SelectedItem.ToString(),
                Feedings    = 0,
                Reviews     = 0,
                Treatments  = 0,
                Honey       = 0,
                Wax         = 0,
                Propolis    = 0,
                Pollen      = 0,
                RoyalJelly  = 0,
                Poison      = 0
            };

            if (apiary == null)
            {
                apiary = db.Query <Apiary>("select * from Apiary where id = " +
                                           int.Parse(_apiary.SelectedItem.ToString().Split().ToArray()[0])).First();
            }
            beehive.ApiaryID = apiary.ID;

            db.Insert(beehive);
            await DisplayAlert(null, "Кошер " + _name.Text + " се добави в пчелинa.", "OK");

            await Navigation.PushAsync(new MainPage(db.DatabasePath));
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Apiary = await _context.Apiaries
                     .Include(a => a.Beekeeper).FirstOrDefaultAsync(m => m.ApiaryId == id);

            if (Apiary == null)
            {
                return(NotFound());
            }
            ViewData["BeekeeperId"] = new SelectList(_context.Beekeepers, "BeekeeperId", "BeekeeperId");
            return(Page());
        }
Beispiel #14
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Apiary = await _context.Apiaries.FindAsync(id);

            if (Apiary != null)
            {
                _context.Apiaries.Remove(Apiary);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <bool> RemoveApiaryAsync(Apiary apiary)
        {
            try
            {
                var tracking = _databaseContext.Apiaries.Remove(apiary);

                await _databaseContext.SaveChangesAsync();

                bool isRemoved = tracking.State == EntityState.Deleted;

                return(isRemoved);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public async Task <bool> AddApiaryAsync(Apiary apiary)
        {
            try
            {
                var tracking = await _databaseContext.AddAsync(apiary);

                await _databaseContext.SaveChangesAsync();

                bool isAdded = tracking.State == EntityState.Added;

                return(isAdded);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #17
0
        public static void Initialize(ApplicationDbContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.SensorTypes.Any())
            {
                return;   // DB has been seeded
            }

            var sensorTypes = new SensorType[]
            {
                new SensorType {
                    TypeDescription = "Hive Temperature"
                },
                new SensorType {
                    TypeDescription = "Hive Mass"
                },
                new SensorType {
                    TypeDescription = "Battery Level"
                },
                new SensorType {
                    TypeDescription = "Ambient Temperature"
                }
            };

            foreach (SensorType s in sensorTypes)
            {
                context.SensorTypes.Add(s);
            }
            context.SaveChanges();

            var apiaries = new Apiary[]
            {
                new Apiary {
                    ApiaryName = "Test Apiary", Postcode = "KT1"
                }
            };

            foreach (Apiary c in apiaries)
            {
                context.Apiaries.Add(c);
            }
            context.SaveChanges();
        }
Beispiel #18
0
        public async Task <int> CreateAsync(
            string userId,
            string apiaryName,
            int capacity)
        {
            var apiary = new Apiary
            {
                ApplicationUserId = userId,
                Name     = apiaryName,
                Capacity = capacity,
            };

            await db.Apiaries.AddAsync(apiary);

            await db.SaveChangesAsync();

            return(apiary.Id);
        }
Beispiel #19
0
        public IActionResult HiveView(int id, string sortOrder)
        {
            ViewBag.Title = "Информация о пасеке";

            ViewData["DateSortParm"] = sortOrder == "Asc" ? "Desc" : "Asc";



            IEnumerable <Apiary> api   = _apiary.Apiaries.Where(i => i.User.Email.Equals(User.Identity.Name)).OrderBy(i => i.Id);
            IEnumerable <Hive>   hives = db.Hives.Where(u => u.Apiary.Id == id);
            IEnumerable <Event>  ev    = db.Events.Where(u => u.Hive.Apiary.Id == id).OrderByDescending(i => i.Date);

            switch (sortOrder)
            {
            case "Asc":
                ev = ev.OrderBy(s => s.Date);
                break;

            default:
                ev = ev.OrderByDescending(s => s.Date);
                break;
            }



            Apiary apiar = api.FirstOrDefault(i => i.Id == id);

            if (apiar == null)
            {
                return(RedirectToAction("", "Apiary"));
            }
            else
            {
                var ap = new ApiaryViewModel
                {
                    Id      = apiar.Id,
                    Map     = apiar.Map,
                    Name    = apiar.Name,
                    Hives   = hives,
                    VEvents = ev,
                };
                return(View(ap));
            }
        }
Beispiel #20
0
        public async Task <IActionResult> Delete(int id)
        {
            IEnumerable <Apiary> api = _apiary.Apiaries.Where(i => i.User.Email.Equals(User.Identity.Name)).OrderBy(i => i.Id);
            Apiary apiar             = api.FirstOrDefault(i => i.Id == id);

            if (apiar == null)
            {
                return(RedirectToAction("", "Apiary"));
            }

            IEnumerable <Event> eve = db.Events.Where(i => i.Hive.Apiary.Id == id).OrderBy(i => i.Id);

            foreach (Event var in eve)
            {
                db.Events.Remove(var);
            }

            IEnumerable <Honey> hon = db.Honey.Where(i => i.Hive.Apiary.Id == id).OrderBy(i => i.Id);

            foreach (Honey dhon in hon)
            {
                db.Honey.Remove(dhon);
            }

            IEnumerable <Inspect> insp = db.Inspects.Where(i => i.Hive.Apiary.Id == id).OrderBy(i => i.Id);

            foreach (Inspect ins in insp)
            {
                db.Inspects.Remove(ins);
            }

            IEnumerable <Hive> hive = db.Hives.Where(i => i.Apiary.Id == id).OrderBy(i => i.Id);

            foreach (Hive var in hive)
            {
                db.Hives.Remove(var);
            }

            db.Apiaries.Remove(apiar);
            await db.SaveChangesAsync();

            return(RedirectToAction("", "Apiary"));
        }
Beispiel #21
0
        public IActionResult Add(int aId)
        {
            ViewBag.Title = "Добавление улья";
            IEnumerable <Apiary> ap = db.Apiaries.Where(i => i.Id == aId && i.User.Email == User.Identity.Name.ToString()).OrderBy(i => i.Id);
            Apiary app = ap.FirstOrDefault(i => i.Id == aId);

            if (app == null)
            {
                return(RedirectToAction("HiveView", "Apiary", new { id = aId }));
            }
            else
            {
                var ap1 = new HiveViewModel
                {
                    Aid = aId,
                };
                return(View(ap1));
            }
        }
        public ActionResult Save(Apiary apiary)
        {
            if (!ModelState.IsValid)
            {
//                var viewModel = new ApiaryFormViewModel(apiary);  //creating an apiaryformviewModel object using apiary parameter
                return(View("ApiaryForm", apiary));
            }
            if (apiary.ApiaryId == 0)
            {
                _context.Apiaries.Add(apiary);
            }
            else
            {
                var apiaryInDb = _context.Apiaries.Single(c => c.ApiaryId == apiary.ApiaryId); //retrieve db version of database
                apiaryInDb.ApiaryName = apiary.ApiaryName;                                     // and update the name
                apiaryInDb.Postcode   = apiary.Postcode;                                       // and postcode  - nb not using tryupdatemodel as a general security risk
            }
            _context.SaveChanges();                                                            //and save updates to database

            return(RedirectToAction("Index", "Apiaries"));                                     //and return to the index list of apiaries
        }
        /// <summary>
        ///     Task to production honey.
        /// </summary>
        /// <param name="apiary">Apiary</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns></returns>
        internal static Task HoneyProductionTask(Apiary apiary, CancellationToken cancellationToken)
        {
            return(Task.Factory.StartNew(() =>
            {
                //Hive id and amount of worker bees from it
                var beesOutside = new Dictionary <int, int>(apiary.Hives.Count);
                apiary.Hives.ForEach(
                    hive => beesOutside.Add(hive.Id, hive.AmountOfWorkerBees - hive.AmountOfBeesInsideHive));

                var rnd = new Random(DateTime.Now.Millisecond);
                while (!cancellationToken.IsCancellationRequested)
                {
                    apiary.Hives.ForEach(hive =>
                    {
                        if (hive.AmountOfBeesInsideHive > hive.AmountOfWorkerBees / 2)
                        {
                            //take 90% of worker bees
                            hive.AmountOfBeesInsideHive = hive.AmountOfWorkerBees * 10 / 100;
                            beesOutside[hive.Id] = hive.AmountOfWorkerBees - hive.AmountOfBeesInsideHive;
                        }
                    });

                    //bees find hive or not
                    if (rnd.Next() % 2 == 0)
                    {
                        //return bees to home
                        var hive = apiary.Hives[rnd.Next(0, apiary.Hives.Count)];
                        var amountToReturn = beesOutside[hive.Id] > hive.AmountOfGuards
                            ? hive.AmountOfGuards
                            : beesOutside[hive.Id];
                        hive.AmountOfBeesInsideHive += amountToReturn;
                        //each bee carries 1 amount of honey
                        hive.AmountOfHoney += amountToReturn;
                    }

                    //Adds some delay
                    Thread.Sleep(50);
                }
            }, cancellationToken));
        }
Beispiel #24
0
        public IActionResult About(int id)
        {
            ViewBag.Title = "Информация о пасеке";
            IEnumerable <Apiary> api = _apiary.Apiaries.Where(i => i.User.Email.Equals(User.Identity.Name)).OrderBy(i => i.Id);
            Apiary apiar             = api.FirstOrDefault(i => i.Id == id);

            if (apiar == null)
            {
                return(RedirectToAction("", "Apiary"));
            }
            else
            {
                var ap = new ApiaryViewModel
                {
                    Id   = apiar.Id,
                    Map  = apiar.Map,
                    Name = apiar.Name,
                    Desc = apiar.Desc
                };
                return(View(ap));
            }
        }
Beispiel #25
0
        private async void AddApiary(object sender, EventArgs e)
        {
            db.CreateTable <Apiary>();

            Apiary lastApiary = db.Table <Apiary>().OrderByDescending(a => a.Date).FirstOrDefault();
            int    id;

            if (lastApiary == null)
            {
                id = 1;
            }
            else
            {
                id = lastApiary.ID++;
            }

            Apiary apiary = new Apiary()
            {
                ID         = id,
                Name       = apiaryName.Text,
                Number     = apiaryNumber.Text,
                Type       = apiaryType.SelectedItem.ToString(),
                Location   = apiaryLocation.Text,
                Date       = DateTime.Now,
                Honey      = 0,
                Wax        = 0,
                Propolis   = 0,
                Pollen     = 0,
                RoyalJelly = 0,
                Poison     = 0
            };

            db.Insert(apiary);
            await DisplayAlert(null, "Пчелин " + apiaryNumber.Text + " е успешно добавен.", "ОК");

            await Navigation.PopAsync();
        }
Beispiel #26
0
        public IActionResult Edit(int id, int aId, int hid)
        {
            ViewBag.Title = "Редактирование события";
            IEnumerable <Apiary> ap  = db.Apiaries.Where(i => i.User.Email == User.Identity.Name.ToString()).OrderBy(i => i.Id);
            Apiary             app   = ap.FirstOrDefault(i => i.Id == aId);
            IEnumerable <Hive> hives = db.Hives.Where(i => i.Apiary.Id == app.Id).OrderBy(i => i.Id);
            Hive hive = hives.FirstOrDefault(i => i.Id == hid);
            IEnumerable <Event> eves = db.Events.Where(i => i.Hive.Apiary.Id == hive.Apiary.Id && i.Hive.Id == hive.Id).OrderBy(i => i.Id);
            Event eve = eves.FirstOrDefault(i => i.Id == id);



            if (app == null || hive == null || eve == null)
            {
                return(RedirectToAction("HiveView", "Apiary", new { id = aId }));
            }
            else
            {
                if (eve.Date < DateTime.Today)
                {
                    return(RedirectToAction("HiveView", "Apiary", new { id = aId }));
                }
                var hv = new EventViewModel
                {
                    Id       = eve.Id,
                    Name     = eve.Name,
                    Desc     = eve.Desc,
                    Date     = eve.Date,
                    Aid      = aId,
                    Hid      = hid,
                    HiveName = eve.Hive.Name,
                    Hives    = hives
                };
                return(View(hv));
            }
        }
Beispiel #27
0
        private async void DoneButton_Clicked(object sender, EventArgs e)
        {
            string firstApiaryNumber  = firstApiaryPicker.SelectedItem.ToString();
            string secondApiaryNumber = secondApiaryPicker.SelectedItem.ToString();

            if (firstApiaryNumber.Equals(secondApiaryNumber))
            {
                var message = DisplayAlert("Грешка", "Избрали сте един и същ пчелин за сравнение!", "Назад");
                if (message.Equals("Назад"))
                {
                    await Navigation.PushAsync(new CompareTwoApiaries(db.DatabasePath));
                }
            }
            else
            {
                Apiary firstSelectedApiary  = GetApiaryWithSameNumber(firstApiaryNumber);
                Apiary secondSelectedApiary = GetApiaryWithSameNumber(secondApiaryNumber);
                compareStack = new StackLayout {
                    Spacing = 2
                };

                Label header1 = new Label
                {
                    FontSize = 30,
                    Text     = "Данни за пчелин 1:"
                };
                compareStack.Children.Add(header1);

                Label name1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Име: {firstSelectedApiary.Name}"
                };
                compareStack.Children.Add(name1);

                Label number1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Номер: {firstSelectedApiary.Number}"
                };
                compareStack.Children.Add(number1);

                Label type1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Тип: {firstSelectedApiary.Type}"
                };
                compareStack.Children.Add(type1);

                Label date1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Дата: {firstSelectedApiary.Date:dd/MM/yyyy HH:mm:ss}"
                };
                compareStack.Children.Add(date1);

                Label production1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Продукция: {firstSelectedApiary.Production}"
                };
                compareStack.Children.Add(production1);

                Label honey1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Мед: {firstSelectedApiary.Honey}"
                };
                compareStack.Children.Add(honey1);

                Label wax1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Восък: {firstSelectedApiary.Wax}"
                };
                compareStack.Children.Add(wax1);

                Label propolis1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Прополис: {firstSelectedApiary.Propolis}"
                };
                compareStack.Children.Add(propolis1);

                Label pollen1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Цветен прашец: {firstSelectedApiary.Pollen}"
                };
                compareStack.Children.Add(pollen1);

                Label royalJelly1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Пчелно млечице: {firstSelectedApiary.RoyalJelly}"
                };
                compareStack.Children.Add(royalJelly1);

                Label poison1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Отрова: {firstSelectedApiary.Poison}"
                };
                compareStack.Children.Add(poison1);

                Label location1 = new Label
                {
                    FontSize = 15,
                    Text     = $"Местоположение: {firstSelectedApiary.Location}"
                };
                compareStack.Children.Add(location1);
                if (firstSelectedApiary.Beehives == null)
                {
                    compareStack.Children.Add(new Label
                    {
                        FontSize = 15,
                        Text     = $"Кошери: Няма въведени кошери."
                    });
                }
                else
                {
                    compareStack.Children.Add(new Label
                    {
                        FontSize = 15,
                        Text     = "Кошери:"
                    });
                    foreach (var beehive in firstSelectedApiary.Beehives)
                    {
                        compareStack.Children.Add(new Label
                        {
                            Text     = beehive.ToString(),
                            FontSize = 10
                        });
                    }
                }

                Label header2 = new Label
                {
                    FontSize = 30,
                    Text     = "Данни за пчелин 2:"
                };
                compareStack.Children.Add(header2);

                Label name2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Име: {secondSelectedApiary.Name}"
                };
                compareStack.Children.Add(name2);

                Label number2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Номер: {secondSelectedApiary.Number}"
                };
                compareStack.Children.Add(number2);

                Label type2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Тип: {secondSelectedApiary.Type}"
                };
                compareStack.Children.Add(type2);

                Label date2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Дата: {secondSelectedApiary.Date:dd/MM/yyyy HH:mm:ss}"
                };
                compareStack.Children.Add(date2);

                Label production2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Продукция: {secondSelectedApiary.Production}"
                };
                compareStack.Children.Add(production2);

                Label honey2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Мед: {secondSelectedApiary.Honey}"
                };
                compareStack.Children.Add(honey1);

                Label wax2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Восък: {secondSelectedApiary.Wax}"
                };
                compareStack.Children.Add(wax2);

                Label propolis2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Прополис: {secondSelectedApiary.Propolis}"
                };
                compareStack.Children.Add(propolis2);

                Label pollen2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Цветен прашец: {secondSelectedApiary.Pollen}"
                };
                compareStack.Children.Add(pollen2);

                Label royalJelly2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Пчелно млечице: {secondSelectedApiary.RoyalJelly}"
                };
                compareStack.Children.Add(royalJelly2);

                Label poison2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Отрова: {secondSelectedApiary.Poison}"
                };
                compareStack.Children.Add(poison2);

                Label location2 = new Label
                {
                    FontSize = 15,
                    Text     = $"Местоположение: {secondSelectedApiary.Location}"
                };
                compareStack.Children.Add(location2);
                if (secondSelectedApiary.Beehives == null)
                {
                    compareStack.Children.Add(new Label
                    {
                        FontSize = 15,
                        Text     = $"Кошери: Няма въведени кошери."
                    });
                }
                else
                {
                    compareStack.Children.Add(new Label
                    {
                        FontSize = 15,
                        Text     = "Кошери:"
                    });
                    foreach (var beehive in secondSelectedApiary.Beehives)
                    {
                        compareStack.Children.Add(new Label
                        {
                            Text     = beehive.ToString(),
                            FontSize = 10
                        });
                    }
                }

                Button button = new Button
                {
                    HorizontalOptions = LayoutOptions.Center,
                    Text            = "Назад",
                    BackgroundColor = Color.CornflowerBlue,
                    TextColor       = Color.White
                };
                button.Clicked += ExitIsClicked;
                compareStack.Children.Add(button);
                Content = new ScrollView
                {
                    Content = compareStack
                };
            }
        }
Beispiel #28
0
        public async Task <IActionResult> Edit(ApiaryViewModel apiaryViewModel)
        {
            ViewBag.Title = "Редактирование пасеки";


            if (ModelState.IsValid)
            {
                IEnumerable <Apiary> api = _apiary.Apiaries.Where(i => i.User.Email.Equals(User.Identity.Name)).OrderBy(i => i.Id);

                Apiary apiar = api.FirstOrDefault(i => i.Name == apiaryViewModel.Name);


                if (apiar == null)
                {
                    string map = apiaryViewModel.Map;
                    if (map != null)
                    {
                        map = apiaryViewModel.Map;
                        int found = apiaryViewModel.Map.IndexOf('"');
                        if (found != -1)
                        {
                            map   = apiaryViewModel.Map.Substring(found);
                            found = map.IndexOf('"');
                            if (found != -1)
                            {
                                map = map.Remove(found);
                            }
                        }
                    }

                    apiar      = _apiary.Apiaries.FirstOrDefault(i => i.Id == apiaryViewModel.Id);
                    apiar.Name = apiaryViewModel.Name;
                    apiar.Map  = map;
                    apiar.Desc = apiaryViewModel.Desc;
                    db.Update(apiar);
                    //await TryUpdateModelAsync<Apiary>(apiar, "", c => c.Name, c => c.Map, c => c.Desc);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("", "Apiary"));
                }
                else
                {
                    apiar = _apiary.Apiaries.FirstOrDefault(i => i.Id == apiaryViewModel.Id);
                    if (apiar.Name == apiaryViewModel.Name)
                    {
                        string map = apiaryViewModel.Map;
                        if (map != null)
                        {
                            int found = apiaryViewModel.Map.IndexOf('"') + 1;
                            if (found != 0)
                            {
                                map   = apiaryViewModel.Map.Substring(found);
                                found = map.IndexOf('"');
                                if (found != -1)
                                {
                                    map = map.Remove(found);
                                }
                            }
                        }


                        apiar.Name = apiaryViewModel.Name;

                        apiar.Map  = map;
                        apiar.Desc = apiaryViewModel.Desc;
                        db.Update(apiar);
                        //await TryUpdateModelAsync<Apiary>(apiar, "", c => c.Name, c => c.Map, c => c.Desc);
                        await db.SaveChangesAsync();

                        return(RedirectToAction("", "Apiary"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Данное Название уже используется");
                        return(View(apiaryViewModel));
                    }
                }
            }
            else
            {
                return(View(apiaryViewModel));
            }
        }
Beispiel #29
0
        /// <remarks>
        /// When the page is initiated, it connects to the database through the database path.
        /// </remarks>
        /// <param name="dbPath">Path of the database.</param>
        public AddBeehiveContentPage(string dbPath)
        {
            db     = new SQLiteConnection(dbPath);
            apiary = null;
            StackLayout stackLayout = new StackLayout();

            stackLayout.BackgroundColor = Color.AliceBlue;

            Label label1 = new Label()
            {
                Text      = "Име на кошер",
                FontSize  = 15,
                TextColor = Color.DarkBlue
            };

            stackLayout.Children.Add(label1);

            _name = new Entry
            {
                Placeholder = "Добавете име на кошер",
                Keyboard    = Keyboard.Text
            };
            stackLayout.Children.Add(_name);

            Label label2 = new Label()
            {
                Text      = "Номер на кошер",
                FontSize  = 15,
                TextColor = Color.DarkBlue
            };

            stackLayout.Children.Add(label2);

            _number = new Entry()
            {
                Placeholder = "Добавете номер на кошер",
                Keyboard    = Keyboard.Text
            };
            stackLayout.Children.Add(_number);

            Label label3 = new Label()
            {
                Text      = "Брой магазини",
                FontSize  = 15,
                TextColor = Color.DarkBlue
            };

            stackLayout.Children.Add(label3);

            _stores = new Entry()
            {
                Placeholder = "Добавете броя на магазините",
                Keyboard    = Keyboard.Text
            };
            stackLayout.Children.Add(_stores);

            Label label4 = new Label()
            {
                Text      = "Пчелин",
                FontSize  = 15,
                TextColor = Color.DarkBlue
            };

            stackLayout.Children.Add(label4);

            _apiary             = new Picker();
            _apiary.Title       = "Избере пчелин";
            _apiary.ItemsSource = db.Table <Apiary>().OrderBy(a => a.ID).ToList();
            stackLayout.Children.Add(_apiary);

            Label label5 = new Label()
            {
                Text      = "Тип кошер",
                FontSize  = 15,
                TextColor = Color.DarkBlue
            };

            stackLayout.Children.Add(label5);

            _typeOfBeehive             = new Picker();
            _typeOfBeehive.Title       = "Изберете тип кошер";
            _typeOfBeehive.ItemsSource = new List <string>
                                         (
                new string[]
            {
                "Лангстрот-Рут",
                "Лангстрот-Рут(8-рамков)",
                "Тръвна",
                "Алпийски кошер Роже Делон",
                "Лежак",
                "Фарар",
                "Многокорпусен кошер",
                "Дадан-Блат",
                "За отглеждане на майка"
            }
                                         );
            stackLayout.Children.Add(_typeOfBeehive);

            Label label6 = new Label()
            {
                Text      = "Тип пчели",
                FontSize  = 15,
                TextColor = Color.DarkBlue
            };

            stackLayout.Children.Add(label6);

            _typeOfBee             = new Picker();
            _typeOfBee.Title       = "Изберете тип пчели";
            _typeOfBee.ItemsSource = new List <string>
                                     (
                new string[]
            {
                "Пчелно семейство",
                "Рояк",
                "Кошер",
                "Отводка"
            }
                                     );
            stackLayout.Children.Add(_typeOfBee);

            _add                 = new Button();
            _add.Text            = "Добави кошер";
            _add.BackgroundColor = Color.CornflowerBlue;
            _add.TextColor       = Color.White;
            _add.Clicked        += Add;
            stackLayout.Children.Add(_add);

            _exit = new Button()
            {
                Text            = "Назад",
                BackgroundColor = Color.CornflowerBlue,
                TextColor       = Color.White,
            };
            _exit.Clicked += Exit;
            stackLayout.Children.Add(_exit);

            ScrollView scrollView = new ScrollView();

            scrollView.Content = stackLayout;
            Content            = scrollView;
        }
 public ApiaryFormViewModel(Apiary apiary)
 {
     Id       = apiary.ApiaryId;
     Name     = apiary.ApiaryName;
     Postcode = apiary.Postcode;
 }