public IHttpActionResult AddLevel([FromBody] Level level) { try { if (!ModelState.IsValid) { return(BadRequest("Missing data for creating the Level")); } if (level.IsDefault) { var result = _levelRepo.ExitDefaultLevel(level.ProjectID); if (result) { return(BadRequest("Already there is a default level")); } } var date = DateTime.Now; level.Created = date; level.Update = date; _levelRepo.Add(level); return(Ok("Level was created successfully")); } catch { return(Json(new { error = "Occurred an error while add the level" })); } }
public void Add_ShouldWork() { var level = new Level() { Description = "Critical" }; var context = _contextFake.GetContext("Add_ShouldWork"); var repo = new LevelRepository(context); repo.Add(level); var result = context.Levels.FirstOrDefault(); Assert.NotNull(result); Assert.Equal(level, result, new LevelComparer()); }