Esempio n. 1
0
        public IActionResult Index()
        {
            ViewBag.Title = "Пасечное хозяйство";

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

            var apObj = new ApiaryViewModel
            {
                Apiaries = api,
            };

            return(View(apObj));
        }
Esempio n. 2
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));
            }
        }
Esempio n. 3
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));
            }
        }
Esempio n. 4
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));
            }
        }
Esempio n. 5
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));
            }
        }