public void Create()
        {
            //Arrange
            int        createdCheckpoint = 0, createdAdmission = 0;
            Checkpoint itemSimple = new Checkpoint()
            {
                Campus      = itemsDTO[1].Campus,
                Row         = itemsDTO[1].Row,
                Description = itemsDTO[1].Description,
                Status      = itemsDTO[1].Status,
                TypeID      = itemsDTO[1].Type.ID,
                IP          = itemsDTO[1].IP
            };
            List <Checkpoint> items = new List <Checkpoint>()
            {
                new Checkpoint
                {
                    ID          = 1,
                    IP          = "192.168.0.1",
                    Campus      = 1,
                    Row         = 4,
                    Description = "На 4 этаже, 425 аудитория",
                    Status      = "Отметка",
                    TypeID      = 2,
                },
                new Checkpoint
                {
                    ID          = 2,
                    IP          = "192.168.0.15",
                    Campus      = 1,
                    Row         = 4,
                    Description = "На 1 этаже на входе",
                    Status      = "Пропуск",
                    TypeID      = 1
                }
            };

            unitWorkMoq.Setup(x => x.Checkpoint.GetAll()).Returns(items);
            unitWorkMoq.Setup(x => x.Checkpoint.Create(It.IsAny <Checkpoint>())).Callback(() =>
            {
                itemSimple.ID = 3;
                createdCheckpoint++;
            });
            unitWorkMoq.Setup(x => x.CheckpointAdmission.Create(It.IsAny <CheckpointAdmission>()))
            .Callback(() =>
            {
                createdAdmission++;
            });

            //Act
            serviceMock.Create(itemsDTO[1]);

            //Assert
            Assert.AreEqual(3, itemSimple.ID);
            Assert.AreEqual(1, createdCheckpoint);
            Assert.AreEqual(2, createdAdmission);
        }
 public IHttpActionResult Post([FromBody] CheckpointDTO item)
 {
     if (item != null)
     {
         service.Create(item);
         return(CreatedAtRoute("DefaultApi", new { id = item.ID }, item));
     }
     return(BadRequest());
 }
 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));
     }
 }