コード例 #1
0
        public ActionResult Create(ResourceViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var model = new Resource();
                    viewModel.MapOntoModel(ref model);
                    var newDoc = new ResourceDoc();
                    viewModel.NewDoc.MapOntoModel(ref newDoc);
                    model.ResourceDocs.Add(newDoc);
                    _resourceRepository.Add(model);
                    _resourceRepository.SaveChanges();

                    return RedirectToAction("Index");
                }
                else
                {
                    return View(viewModel);
                }
            }
            catch(Exception ex)
            {
                _logger.Error("ResourcesController.Create", ex);
                ModelState.AddModelError("", ex);
                return View(viewModel);
            }
        }
コード例 #2
0
        public ActionResult Create()
        {
            var viewModel = new ResourceViewModel();

            return View(viewModel);
        } 
コード例 #3
0
        public ActionResult CreateField(ResourceViewModel viewModel)
        {
            //if (ModelState.IsValid)
            //{
            var resource = _resourceRepository.GetById(viewModel.Id);
            var field = new Field()
                            {
                                Resource = resource,
                                Name = viewModel.NewField.Name,
                                FieldType = viewModel.NewField.FieldType
                            };

            field.FieldDocs.Add(new FieldDoc()
                                    {
                                        Language = Configuration.DefaultLanguage,
                                        Description = viewModel.NewField.Description,
                                        Field = field
                                    });

            resource.Fields.Add(field);

            _resourceRepository.Save(resource);
            _resourceRepository.SaveChanges();

            return RedirectToAction("Edit", new { id = viewModel.Id });
            //}
            //else
            //{
            //    return View("Edit", viewModel);
            //}

        }
コード例 #4
0
        public ActionResult CreateResourceDoc(ResourceViewModel viewModel)
        {
            //if (ModelState.IsValid)
            //{
                var resource = _resourceRepository.GetById(viewModel.Id);
                var doc = new ResourceDoc() { Resource = resource };
                viewModel.NewDoc.MapOntoModel(ref doc);
                resource.ResourceDocs.Add(doc);
                _resourceRepository.SaveChanges();

                return RedirectToAction("Edit", new { id = viewModel.Id });
            //}
            //else
            //{
            //    return View("Edit", viewModel);
            //}

        }
コード例 #5
0
        public ActionResult Delete(ResourceViewModel viewModel)
        {
            try
            {
                _resourceRepository.DeleteById(viewModel.Id);
                _resourceRepository.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
コード例 #6
0
        public ActionResult Edit(ResourceViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var resource = _resourceRepository.GetById(viewModel.Id);
                    viewModel.MapOntoModel(ref resource);
                    _resourceRepository.Save(resource);
                    _resourceRepository.SaveChanges();

                    return RedirectToAction("Index");
                }
                else
                {
                    return View(viewModel);
                }
            }
            catch
            {
                return View();
            }
        }