public ActionResult New(string tab = "main_tab")
        {
            ViewBag.ShopMenuActive = "active open";
            ViewBag.ShopActive     = "active open";
            ViewBag.Tab            = tab;

            var model = new AddEditShopForm();

            _filesRepo.BuildUrl("dasdadas");
            return(View(model));
        }
        public ActionResult New(AddEditShopForm model, string tab = "main_tab")
        {
            ViewBag.ShopMenuActive = "active open";
            ViewBag.ShopActive     = "active open";
            ViewBag.Tab            = tab;

            if (!ModelState.IsValid)
            {
                return(View(model)
                       //this extension breaks default MVC validation
                       //.WithWarning("Some fields are invalid!")
                       );
            }

            var shop = new Shop();

            //TODO - это нужно сделать automapper'ом
            shop.Name             = model.MainTab.Name;
            shop.ShortDescription = model.MainTab.ShortDescription;
            shop.FullDescription  = model.MainTab.FullDescription;
            shop.Address          = model.MainTab.Address;
            shop.Phone            = model.MainTab.Phone;
            shop.Email            = model.MainTab.Email;
            shop.IsKosher         = model.MainTab.IsKosher;
            shop.SeoUrl           = model.MainTab.SeoUrl;
            shop.Theme            = model.MainTab.Theme;
            shop.OwnerID          = model.MainTab.OwnerID.Value;

            if (model.MainTab.Image != null)
            {
                var imageId = _filesRepo.Create(model.MainTab.Image.InputStream, model.MainTab.Image.FileName, new[] { "jpg", "png", "jpeg", "bmp" });
                shop.ImagePath = _filesRepo.BuildUrl(imageId);
                shop.HasImage  = true;
            }
            if (model.MainTab.Logo != null)
            {
                var logoId = _filesRepo.Create(model.MainTab.Logo.InputStream, model.MainTab.Logo.FileName, new[] { "jpg", "png", "jpeg", "bmp" });
                shop.LogoPath = _filesRepo.BuildUrl(logoId);
            }
            if (model.MainTab.Favicon != null)
            {
                var favId = _filesRepo.Create(model.MainTab.Favicon.InputStream, model.MainTab.Favicon.FileName, new[] { "jpg", "png", "jpeg", "ico" });
                shop.FaviconPath = _filesRepo.BuildUrl(favId);
            }

            _context.Shops.Add(shop);
            _context.SaveChanges();

            return(RedirectToAction <ShopController>(c => c.Table()));
        }
        public ActionResult Edit(AddEditShopForm model)
        {
            if (!ModelState.IsValid)
            {
                return(JsonValidationError());
            }

            var shop = _context.Shops.SingleOrDefault(i => i.ID == model.ID);

            if (shop == null)
            {
                return(JsonError("Cannot find the product specified."));
            }

            // ToDo Update Shop

            _context.SaveChanges();

            return(Json(new { success = true }));
        }