// GET: DataLayers
        public IEnumerable<DataLayerApiViewModel> GetAllDataLayers()
        {
            IDisposable context;

            var dataLayersRepository = new DataLayersRepository();
            var layers = dataLayersRepository.GetAll(out context).ToList();

            var result = layers.Select(layer => new DataLayerApiViewModel(layer)).ToList();

            context.Dispose();

            return result;
        }
        // GET: BaseLayers/Create
        public ActionResult Add()
        {
            var baseLayersRepository = new BaseLayersRepository();
            IDisposable context = null;

            ViewBag.ListOfBaseLayers = baseLayersRepository.GetAll(out context).ToList().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text = x.Name
            });

            context?.Dispose();

            var dataLayersRepository = new DataLayersRepository();
            ViewBag.ListOfDataLayers = dataLayersRepository.GetAll(out context).ToList().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text = x.Name
            });
            context?.Dispose();

            return View(new DataLayer());
        }
        // GET: BaseLayers/Create
        public ActionResult Add()
        {
            var dataLayersRepository = new DataLayersRepository();
            var regionsRepository = new RegionsRepository();

            IDisposable context = null;

            ViewBag.ListOfRegions = regionsRepository.GetAll(out context).ToList().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text = x.Name
            });

            context?.Dispose();

            var baseLayersRepository = new BaseLayersRepository();
            IDisposable context3;

            var baseLayers = baseLayersRepository.GetAll(out context3).ToList();

            ViewBag.BaseLayerUrl = baseLayers.FirstOrDefault()?.Url;
            context3?.Dispose();

            IDisposable context1;

            ViewBag.ListOfDataLayers = dataLayersRepository.GetAll(out context1).ToList().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text = x.Name
            });

            using (context1)
            {
                return View(new EditPointViewModel(new Point()));
            }
        }
        // GET: BaseLayers/Edit/5
        public ActionResult Edit(long id)
        {
            var dataLayersRepository = new DataLayersRepository();
            var pointsRepository = new PointsRepository();
            var regionsRepository = new RegionsRepository();

            var model = pointsRepository.GetById(id);
            var dataLayersIds = model.DataLayers != null ? model.DataLayers.Select(x => x.Id) : new List<long>();

            IDisposable context;

            ViewBag.ListOfDataLayers = dataLayersRepository.GetAll(out context).ToList().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text = x.Name,
                Selected = dataLayersIds.Contains(x.Id)
            });

            context?.Dispose();

            IDisposable context1 = null;

            ViewBag.ListOfRegions = regionsRepository.GetAll(out context1).ToList().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text = x.Name
            });

            context1?.Dispose();

            var baseLayersRepository = new BaseLayersRepository();
            IDisposable context3;

            var baseLayers = baseLayersRepository.GetAll(out context3).ToList();

            ViewBag.BaseLayerUrl = baseLayers.FirstOrDefault()?.Url;
            context3?.Dispose();

            if (model != null)
                return View(new EditPointViewModel(model));
            return HttpNotFound();
        }
        // GET: BaseLayers
        public ActionResult Index()
        {
            var dataLayersRepository = new DataLayersRepository();

            IDisposable context;
            var layers = dataLayersRepository.GetAll(out context).ToList().Select(x => new DataLayerViewModel(x)).ToList();

            using (context)
            {
                return View(layers);
            }
        }
        // GET: BaseLayers/Edit/5
        public ActionResult Edit(long id)
        {
            var baseLayersRepository = new BaseLayersRepository();
            IDisposable context;

            ViewBag.ListOfBaseLayers = baseLayersRepository.GetAll(out context).ToList().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text = x.Name
            });
            context?.Dispose();

            var dataLayersRepository = new DataLayersRepository();
            ViewBag.ListOfDataLayers = dataLayersRepository.GetAll(out context).ToList().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text = x.Name
            });
            context?.Dispose();

            var model = dataLayersRepository.GetById(id);

            if (model != null)
                return View(model);
            return HttpNotFound();
        }