public ActionResult Create(AdmissionViewModel model)
 {
     if (string.IsNullOrEmpty(model.Description))
     {
         ModelState.AddModelError("Description", "Описание должно быть заполнено");
     }
     if (string.IsNullOrEmpty(model.Role))
     {
         ModelState.AddModelError("Role", "Выберите роль");
     }
     if (ModelState.IsValid)
     {
         service.Create(new Admission
         {
             Description = model.Description,
             Role        = model.Role
         });
         return(RedirectToAction("Index", "Admission"));
     }
     else
     {
         model.RoleList = new SelectList(new List <StatusForList> {
             new StatusForList {
                 Key     = "Сотрудник",
                 Display = "Сотрудник"
             },
             new StatusForList {
                 Key     = "Студент",
                 Display = "Студент"
             }
         },
                                         "Key", "Display");
         return(View(model));
     }
 }
Beispiel #2
0
 public IHttpActionResult Post([FromBody] Admission item)
 {
     if (item != null)
     {
         service.Create(item);
         return(CreatedAtRoute("DefaultApi", new { id = item.ID }, item));
     }
     return(BadRequest());
 }
Beispiel #3
0
        public void Create()
        {
            //Arrange
            int       createdAdmission = 0;
            Admission item             = new Admission()
            {
                Role        = "Уборщица",
                Description = "Вход в аудиторию 402"
            };

            unitWorkMoq.Setup(x => x.Admission.Create(It.IsAny <Admission>())).Callback(() =>
            {
                item.ID = 3;
                createdAdmission++;
            });

            //Act
            serviceMock.Create(item);

            //Assert
            Assert.AreEqual(3, item.ID);
            Assert.AreEqual(1, createdAdmission);
        }