Inheritance: DomainObject
コード例 #1
0
ファイル: UnitController.cs プロジェクト: ucdavis/Catbert
        public ActionResult Create(Unit unit)
        {
            var unitToCreate = new Unit();

            Mapper.Map(unit, unitToCreate);

            unitToCreate.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _unitRepository.EnsurePersistent(unitToCreate);

                Message = "Unit Created Successfully";

                return RedirectToAction("Index");
            }
            else
            {
                var viewModel = UnitViewModel.Create(Repository);
                viewModel.Unit = unit;

                return View(viewModel);
            }
        }
コード例 #2
0
ファイル: UnitController.cs プロジェクト: ucdavis/Catbert
        public ActionResult Delete(int id, Unit unit)
        {
            var unitToDelete = _unitRepository.GetNullableById(id);

            if (unitToDelete == null) return RedirectToAction("Index");

            _unitRepository.Remove(unitToDelete);

            Message = "Unit Removed Successfully";

            return RedirectToAction("Index");
        }
コード例 #3
0
ファイル: UnitController.cs プロジェクト: ucdavis/Catbert
        public ActionResult Edit(int id, Unit unit)
        {
            var unitToEdit = _unitRepository.GetNullableById(id);

            if (unitToEdit == null) return RedirectToAction("Index");

            Mapper.Map(unit, unitToEdit);

            unitToEdit.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _unitRepository.EnsurePersistent(unitToEdit);

                Message = "Unit Edited Successfully";

                return RedirectToAction("Index");
            }
            else
            {
                var viewModel = UnitViewModel.Create(Repository);
                viewModel.Unit = unit;

                return View(viewModel);
            }
        }
コード例 #4
0
 public static Unit Unit(int? counter, bool populateAllFields = false)
 {
     var rtValue = new Unit();
     rtValue.FullName = "FullName" + counter.Extra();
     rtValue.FisCode = "F" + counter.Extra();
     rtValue.School = new School();
     rtValue.ShortName = "ShortName" + counter.Extra();
     if (populateAllFields)
     {
         //rtValue.ShortName = "x".RepeatTimes(50);
         rtValue.PpsCode = counter.Extra();
     }
     return rtValue;
 }