Create() public static method

public static Create ( IRepository repository ) : UnitViewModel
repository IRepository
return UnitViewModel
Example #1
0
        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));
            }
        }
Example #2
0
        //
        // GET: /Unit/Edit/5
        public ActionResult Edit(int id)
        {
            var unit = _unitRepository.GetNullableById(id);

            if (unit == null)
            {
                return(RedirectToAction("Index"));
            }

            var viewModel = UnitViewModel.Create(Repository);

            viewModel.Unit = unit;

            return(View(viewModel));
        }
Example #3
0
        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));
            }
        }
Example #4
0
        // GET: /Unit/Create
        public ActionResult Create()
        {
            var viewModel = UnitViewModel.Create(Repository);

            return(View(viewModel));
        }