Ejemplo n.º 1
0
        // GET api/admissions/5
        /// <summary>
        /// Gets a <see cref="Admission"/> object from the repository.
        /// </summary>
        /// <param name="id">The ID of <see cref="Admission"/>.</param>
        /// <returns>The <see cref="Admission"/> with the given ID.</returns>
        public IHttpActionResult Get(int id)
        {
            Admission item = service.Get(id);

            if (item != null)
            {
                return(Ok(item));
            }
            else
            {
                return(NotFound());
            }
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var item = service.Get(id);

            if (item != null)
            {
                return(PartialView(item));
            }
            return(HttpNotFound());
        }
Ejemplo n.º 3
0
        public void Get()
        {
            //Arrange
            unitWorkMoq.Setup(x => x.Admission.Get(1)).Returns(itemsAdmission[0]);
            unitWorkMoq.Setup(x => x.Admission.Get(2)).Returns(itemsAdmission[1]);

            //Act
            var result = serviceMock.Get(id);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Admission));
            Assert.AreEqual(id, result.ID);
        }
 public ActionResult Create(CheckpointViewModel model)
 {
     if (string.IsNullOrEmpty(model.IP))
     {
         ModelState.AddModelError("IP", "IP должен быть заполнен");
     }
     if (model.Campus == null)
     {
         ModelState.AddModelError("Campus", "Корпус должен быть заполнен");
     }
     if (model.Row == null)
     {
         ModelState.AddModelError("Row", "Этаж должен быть заполнен");
     }
     if (string.IsNullOrEmpty(model.Description))
     {
         ModelState.AddModelError("Description", "Описание должно быть заполнено");
     }
     if (string.IsNullOrEmpty(model.Status))
     {
         ModelState.AddModelError("Status", "Выберите статус");
     }
     if (string.IsNullOrEmpty(model.TypeID))
     {
         ModelState.AddModelError("TypeID", "Выберите тип");
     }
     if (ModelState.IsValid)
     {
         List <Admission> admissions = new List <Admission>();
         foreach (var item in model.AdmissionList)
         {
             if (item.IsChecked)
             {
                 admissions.Add(admissionService.Get(item.ID));
             }
         }
         model.Admissions = admissions;
         model.Type       = (TypeDTO)typeService.Get(System.Convert.ToInt32(model.TypeID));
         checkpointService.Create(new CheckpointDTO
         {
             IP          = model.IP,
             Campus      = (int)model.Campus,
             Row         = (int)model.Row,
             Classroom   = model.Classroom,
             Section     = model.Section,
             Description = model.Description,
             Status      = model.Status,
             Type        = model.Type,
             Admissions  = model.Admissions
         });
         return(RedirectToAction("Index", "Checkpoint"));
     }
     else
     {
         List <StatusForList> types = new List <StatusForList>();
         foreach (Type item in typeService.GetAll())
         {
             types.Add(new StatusForList
             {
                 Key     = item.ID.ToString(),
                 Display = item.Description
             });
         }
         List <CheckboxItem> admissions = new List <CheckboxItem>();
         foreach (var item in admissionService.GetAll())
         {
             string display = item.Role + " (" + item.Description + ")";
             admissions.Add(new CheckboxItem()
             {
                 ID        = item.ID,
                 Display   = display,
                 IsChecked = false
             });
         }
         model.StatusList = new SelectList(new List <StatusForList> {
             new StatusForList {
                 Key     = "Пропуск",
                 Display = "Пропуск"
             },
             new StatusForList {
                 Key     = "Отметка",
                 Display = "Отметка"
             }
         },
                                           "Key", "Display");
         model.TypeList      = new SelectList(types, "Key", "Display");
         model.AdmissionList = admissions;
         return(View(model));
     }
 }