public ActionResult <EntityBase> Create([FromBody] LevelCreateViewModel level) { var newId = _repo.Add(_mapper.Map <Level>(level)); return(Created(nameof(GetById), new EntityBase { Id = newId })); }
//[Authorize(Policy = "CreateRolePolicy")] public async Task <IActionResult> Create(LevelCreateViewModel model) { if (ModelState.IsValid) { Level level = new Level { Name = model.Level.Name, Description = model.Level.Description }; var dept = await levelService.AddLevel(level); ViewBag.message = $"Employee {model.Level.Name} is successfullly saved to DataBase"; return(RedirectToAction("details", new { id = level.Id })); } return(View()); }
public void Create_ShouldWork() { var context = _contextFake.GetContext("Create_ShouldWork") .AddFakeLevels(); var repo = new LevelRepository(context); var controller = new LevelController(repo, _mapper); var newLevel = new LevelCreateViewModel() { Description = "New Level" }; var result = controller.Create(newLevel); Assert.IsType <ActionResult <EntityBase> >(result); var actionResult = Assert.IsType <CreatedResult>(result.Result); var valueResult = Assert.IsType <EntityBase>(actionResult.Value); var actual = context.Levels.SingleOrDefault(x => x.Id == valueResult.Id); Assert.Equal(newLevel.Description, actual.Description); }