Exemple #1
0
        public ActionResult Create(ModelCreateEditViewModel modelCreateEditViewModel)
        {
            Model model = new Model();

            if(ModelState.IsValid)
            {
                model.Id = Guid.NewGuid();
                model.WebSiteId = modelCreateEditViewModel.SelectedWebSite;
                model.Name = modelCreateEditViewModel.Name;
                db.Models.Add(model);
                db.SaveChanges();

                // Create Model Folder
                string basePath = @"Content\Models";
                DirectoryInfo dInfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + basePath);
                dInfo.CreateSubdirectory(model.Name.Replace(" ", string.Empty) + @"\ImageGalleries");
                dInfo.CreateSubdirectory(model.Name.Replace(" ", string.Empty) + @"\Videos");

                return RedirectToAction("Manage");
            }

            return View(model);
        }
Exemple #2
0
        public ActionResult Edit(ModelCreateEditViewModel modelCreateEditViewModel)
        {
            Model model = this.db.Models.Find(modelCreateEditViewModel.Model.Id);

            if(ModelState.IsValid)
            {
                db.Entry(model).State = EntityState.Modified;
                model.Name = modelCreateEditViewModel.Name;
                model.WebSiteId = modelCreateEditViewModel.SelectedWebSite;

                db.SaveChanges();
                return RedirectToAction("Manage");
            }
            else
            {
                var viewModel = new ModelCreateEditViewModel
                {
                    Model = modelCreateEditViewModel.Model,
                    Name = modelCreateEditViewModel.Model.Name,
                    SelectedWebSite = modelCreateEditViewModel.Model.WebSiteId,
                };

                return View("Edit", viewModel);
            }
        }
Exemple #3
0
        //
        // GET: /Model/Edit/5
        public ActionResult Edit(Guid id)
        {
            ModelCreateEditViewModel modelCreateEditViewModel = new ModelCreateEditViewModel();
            modelCreateEditViewModel.Model = this.db.Models.Find(id);

            var viewModel = new ModelCreateEditViewModel
            {
                Model = modelCreateEditViewModel.Model,
                Name = modelCreateEditViewModel.Model.Name,
                SelectedWebSite = modelCreateEditViewModel.Model.WebSiteId
            };

            return View(viewModel);
        }