public void Edit()
        {
            //Arrange
            int updatedCheckpoint = 0, updatedAdmission = 0, deletedAdmission = 0;

            unitWorkMoq.Setup(x => x.Checkpoint.Update(It.IsAny <Checkpoint>())).Callback(() =>
            {
                updatedCheckpoint++;
            });
            unitWorkMoq.Setup(x => x.Checkpoint.GetAll()).Returns(itemsSimple);
            unitWorkMoq.Setup(x => x.CheckpointAdmission.GetAll()).Returns(itemsCheckpointAdmission);
            unitWorkMoq.Setup(x => x.CheckpointAdmission.Create(It.IsAny <CheckpointAdmission>()))
            .Callback(() =>
            {
                updatedAdmission++;
            });
            unitWorkMoq.Setup(x => x.CheckpointAdmission.Delete(It.IsAny <int>()))
            .Callback(() =>
            {
                deletedAdmission++;
            });

            //Act
            serviceMock.Edit(itemsDTO[0]);

            //Assert
            Assert.AreNotEqual(0, updatedCheckpoint);
            Assert.AreNotEqual(0, updatedAdmission);
            Assert.AreNotEqual(0, deletedAdmission);
            Assert.AreEqual(1, updatedCheckpoint);
            Assert.AreEqual(2, updatedAdmission);
            Assert.AreEqual(2, deletedAdmission);
        }
 public IHttpActionResult Put(int id, [FromBody] CheckpointDTO item)
 {
     if (item != null)
     {
         if (id == item.ID)
         {
             service.Edit(item);
             return(Ok(item));
         }
     }
     return(BadRequest());
 }
 public ActionResult Edit(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.Edit(new CheckpointDTO
         {
             ID          = model.ID,
             IP          = model.IP,
             Campus      = (int)model.Campus,
             Classroom   = model.Classroom,
             Section     = model.Section,
             Row         = (int)model.Row,
             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 + ")";
             if (checkpointService.IsMatchAdmission(model.ID, item.ID))
             {
                 admissions.Add(new CheckboxItem()
                 {
                     ID        = item.ID,
                     Display   = display,
                     IsChecked = true
                 });
             }
             else
             {
                 admissions.Add(new CheckboxItem()
                 {
                     ID        = item.ID,
                     Display   = display,
                     IsChecked = false
                 });
             }
         }
         model = new CheckpointViewModel
         {
             ID         = model.ID,
             StatusList = new SelectList(new List <StatusForList> {
                 new StatusForList {
                     Key     = "Пропуск",
                     Display = "Пропуск"
                 },
                 new StatusForList {
                     Key     = "Отметка",
                     Display = "Отметка"
                 }
             },
                                         "Key", "Display"),
             TypeList      = new SelectList(types, "Key", "Display"),
             AdmissionList = admissions
         };
         return(View(model));
     }
 }