Пример #1
0
 public bool DeleteUnit(Unit unit)
 {
     if (unit == null) return false;
     _unitOfWork.UnitRepository.Delete(unit);
     _unitOfWork.Save();
     return true;
 }
Пример #2
0
 public void CanDoPostBackEdit()
 {
     //ACT
     var unit = new Unit {UnitID = 1, Name = "Mt"};
     var result = _unitController.Edit(unit);
     //Assert
     Assert.IsInstanceOf<ActionResult>(result);
     Assert.IsInstanceOf<Unit>(unit.UnitID);
 }
Пример #3
0
 public void CanDoPostBackCreate()
 {
     //ACT
     var unit = new Unit {Name = "Litre"};
     var result = _unitController.Create(unit);
     //Assert
     Assert.IsInstanceOf<ActionResult>(result);
     Assert.IsInstanceOf<int>(unit.UnitID);
 }
Пример #4
0
        public virtual ActionResult Create(Unit unit)
        {
            if (ModelState.IsValid)
            {
                _unitService.AddUnit(unit);
                return Json(new { success = true });
            }

            return PartialView(unit);
        }
Пример #5
0
        public virtual ActionResult Edit(Unit unit)
        {
            if (ModelState.IsValid)
            {
                var origin = _unitService.FindById(unit.UnitID);
                origin.Name = unit.Name;

                _unitService.EditUnit(origin);

                //return RedirectToAction("Index");
                return Json(new { success = true });
            }

            ViewBag.UnitID = new SelectList(_unitService.GetAllUnit(), "UnitID", "Name", unit.UnitID);
            return PartialView(unit);
        }
Пример #6
0
 public bool EditUnit(Unit unit)
 {
     _unitOfWork.UnitRepository.Edit(unit);
     _unitOfWork.Save();
     return true;
 }
Пример #7
0
 public bool AddUnit(Unit unit)
 {
     _unitOfWork.UnitRepository.Add(unit);
     _unitOfWork.Save();
     return true;
 }
Пример #8
0
 private Unit BindUnit(UnitViewModel model)
 {
     if (model == null) return null;
     var unit = new Unit()
         {
             UnitID = model.UnitID,
             Name = model.UnitName
         };
     return unit;
 }