public ActionResult Index(int?page) { int pageSize = 50; int pageNumber = (page ?? 1); return(View(checkpointService.GetAll().ToPagedList(pageNumber, pageSize))); }
// GET api/checkpoints /// <summary> /// Gets all <see cref="CheckpointDTO"/> from repository. /// </summary> /// <returns>The collection of all <see cref="CheckpointDTO"/> from the repository.</returns> public IHttpActionResult Get() { IEnumerable <CheckpointDTO> items = service.GetAll(); if (items != null) { return(Ok(items)); } else { return(NotFound()); } }
public void Get_All() { //Arrange unitWorkMoq.Setup(x => x.Checkpoint.GetAll()).Returns(itemsSimple); unitWorkMoq.Setup(x => x.Checkpoint.Get(1)).Returns(itemsSimple[0]); unitWorkMoq.Setup(x => x.Checkpoint.Get(2)).Returns(itemsSimple[1]); unitWorkMoq.Setup(x => x.Type.Get(1)).Returns(itemsType[0]); unitWorkMoq.Setup(x => x.Type.Get(2)).Returns(itemsType[1]); unitWorkMoq.Setup(x => x.Type.Get(3)).Returns(itemsType[2]); unitWorkMoq.Setup(x => x.CheckpointAdmission.GetAll()).Returns(itemsCheckpointAdmission); unitWorkMoq.Setup(x => x.Admission.GetAll()).Returns(itemsAdmission); //Act var result = serviceMock.GetAll(); //Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(List <CheckpointDTO>)); Assert.AreEqual(2, result.ToList().Count); }
public ActionResult Create(ActivityViewModel model) { if (string.IsNullOrEmpty(model.IdentityGUID)) { ModelState.AddModelError("IdentityGUID", "GUID пользователя должен быть заполнен"); } if (string.IsNullOrEmpty(model.CheckpointIP)) { ModelState.AddModelError("CheckpointIP", "IP должен быть заполнен"); } if (!model.Date.HasValue) { ModelState.AddModelError("Date", "Выберите дату"); } if (string.IsNullOrEmpty(model.Status)) { ModelState.AddModelError("Status", "Выберите статус"); } if (string.IsNullOrEmpty(model.Mode)) { ModelState.AddModelError("Mode", "Выберите режим"); } var user = identityService.GetAll().Where(x => x.GUID.Equals(model.IdentityGUID)).FirstOrDefault(); if (user == null) { ModelState.AddModelError("IdentityGUID", "Данного пользователя не существует"); } var checkpoint = checkpointService.GetAll().Where(x => x.IP.Equals(model.CheckpointIP)).FirstOrDefault(); if (checkpoint == null) { ModelState.AddModelError("CheckpointIP", "Данного датчика не существует"); } if (ModelState.IsValid) { bool status; if (model.Status.Equals("Успех")) { status = true; } else { status = false; } service.Create(new Activity { IdentityGUID = model.IdentityGUID, CheckpointIP = model.CheckpointIP, Date = (System.DateTime)model.Date, ModeID = modeService.GetByMode(model.Mode).FirstOrDefault().ID, Status = status }); return(RedirectToAction("Index", "Activity")); } else { model = new ActivityViewModel { StatusList = new SelectList(new List <StatusForList> { new StatusForList { Key = "Успех", Display = "Успех" }, new StatusForList { Key = "Неудача", Display = "Неудача" } }, "Key", "Display"), ModeList = new SelectList(new List <StatusForList> { new StatusForList { Key = "Вход", Display = "Вход" }, new StatusForList { Key = "Выход", Display = "Выход" } }, "Key", "Display") }; return(View(model)); } }