public BaseLayerViewModel(BaseLayer layer)
 {
     Id = layer.Id;
     Name = layer.Name;
     Description = layer.Description;
     Url = layer.Url;
     if (layer.DataLayers != null)
         DataLayers = layer.DataLayers.ToList().Select(x=> new DataLayerViewModel(x)).ToList();
 }
        public long Update(BaseLayer model)
        {
            using (var context = new OpenMuseumContext())
            {
                context.Entry(model).State = EntityState.Modified;
                context.SaveChanges();

                return model.Id;
            }
        }
 public BaseLayerApiViewModel(BaseLayer layer)
 {
     Id = layer.Id;
     Name = layer.Name;
     Description = layer.Description;
     Url = layer.Url;
     Default = layer.Default;
     Height = layer.Height;
     Width = layer.Width;
     Regions = layer.Regions.ToList().Select(region => new RegionApiViewModel(region)).ToList();
 }
        public long Add(BaseLayer model)
        {
            using (var context = new OpenMuseumContext())
            {
                var result = context.BaseLayers.Add(model);
                context.Entry(result).State = EntityState.Added;
                context.SaveChanges();

                return result.Id;
            }
        }
        public ActionResult Add(BaseLayer model)
        {
            try
            {
                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];

                    if (file != null && file.ContentLength > 0)
                    {
                        if (IsValidMap(file))
                        {
                            var uniqId = Guid.NewGuid();
                            var fileName = uniqId + Path.GetExtension(file.FileName);
                            var path = Path.Combine(Server.MapPath("~/App_Data/"), fileName);
                            file.SaveAs(path);

                            model.UniqId = uniqId;
                            model.Url = GetCurrentDomain(Request) + "/Public/" + uniqId + "/{z}/{x}/{y}.png";

                            var extractPath = Path.Combine(Server.MapPath("~/Public/"), uniqId.ToString());
                            ZipFile.ExtractToDirectory(path, extractPath);

                            var baseLayersRepository = new BaseLayersRepository();

                            baseLayersRepository.Add(model);

                            return RedirectToAction("Index");
                        }
                    }
                }

                return View();
            }
            catch
            {
                return View();
            }
        }