Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cross Platform Apps with Angular and ASP.NET Core

Cross Platform Apps with Angular and ASP.NET Core

Angular provides web developers a platform where applications can be written not only for the web. Mobile devices such as smartphones or tablets, as well as the desktop also consume line of business (LOB) apps and are indispensable. Once the angular code has been written, it doesn't take much to port the application to the smartphone or desktop. In this talk, Fabian Gosebrink shows how an existing angular application can be ported to a mobile device with a few steps using Capacitor and how native features can also be used. With Electron, the desktop is also used as a platform, so that at the end a code base can serve all platforms and the application can be used via any end device.

Fabian Gosebrink

December 03, 2022
Tweet

More Decks by Fabian Gosebrink

Other Decks in Technology

Transcript

  1. Cross Platform Apps
    .NET Core

    View Slide

  2. Client

    View Slide

  3. Client

    View Slide

  4. View Slide

  5. namespace DoggoApi.Controllers
    {
    [ApiController]
    [Route("api/[controller]")]
    [Authorize("access:api")]
    public class DoggosController : ControllerBase
    {
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37

    View Slide

  6. namespace DoggoApi.Controllers
    {
    [ApiController]
    [Route("api/[controller]")]
    [Authorize("access:api")]
    public class DoggosController : ControllerBase
    {
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    [Authorize("access:api")]
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37

    View Slide

  7. namespace DoggoApi.Controllers
    {
    [ApiController]
    [Route("api/[controller]")]
    [Authorize("access:api")]
    public class DoggosController : ControllerBase
    {
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    [Authorize("access:api")]
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37

    View Slide

  8. namespace DoggoApi.Controllers
    {
    [ApiController]
    [Route("api/[controller]")]
    [Authorize("access:api")]
    public class DoggosController : ControllerBase
    {
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    [Authorize("access:api")]
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    [Authorize( access:api )]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    {
    38
    return BadRequest();
    39
    }
    40
    41
    /* ... */
    42

    View Slide

  9. namespace DoggoApi.Controllers
    {
    [ApiController]
    [Route("api/[controller]")]
    [Authorize("access:api")]
    public class DoggosController : ControllerBase
    {
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    [Authorize("access:api")]
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    {
    return BadRequest();
    }
    /* ... */
    await _hubContext.Clients.All.SendAsync("DoggoAdded", dto);
    return CreatedAtRoute(nameof(GetSingleDoggo),
    new { id = newItem?.Id }, dto);
    }
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    [HttpPut]
    50
    [Route("rate/{id:guid}", Name = nameof(RateDoggo))]
    51
    [AllowAnonymous]
    52
    public async Task> RateDoggo(
    53
    Guid id, [FromBody] DoggoRateDto rateDto)
    54
    {
    55
    if (rateDto == null)
    56
    {
    57
    return BadRequest();
    58

    View Slide

  10. namespace DoggoApi.Controllers
    {
    [ApiController]
    [Route("api/[controller]")]
    [Authorize("access:api")]
    public class DoggosController : ControllerBase
    {
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    [Authorize("access:api")]
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    33
    34
    35
    36
    37
    await _hubContext.Clients.All.SendAsync("DoggoAdded", dto);
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    {
    38
    return BadRequest();
    39
    }
    40
    41
    /* ... */
    42
    43
    44
    45
    return CreatedAtRoute(nameof(GetSingleDoggo),
    46
    new { id = newItem?.Id }, dto);
    47
    }
    48
    49
    [HttpPut]
    50
    [Route("rate/{id:guid}", Name = nameof(RateDoggo))]
    51
    [AllowAnonymous]
    52
    public async Task> RateDoggo(
    53
    Guid id, [FromBody] DoggoRateDto rateDto)
    54
    {
    55
    if (rateDto == null)
    56
    {
    57
    return BadRequest();
    58
    }
    59
    60
    DoggoEntity? existingEntity = _repository.GetSingle(id);
    61
    62

    View Slide

  11. namespace DoggoApi.Controllers
    {
    [ApiController]
    [Route("api/[controller]")]
    [Authorize("access:api")]
    public class DoggosController : ControllerBase
    {
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    [Authorize("access:api")]
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    33
    34
    35
    36
    37
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpPut]
    [Route("rate/{id:guid}", Name = nameof(RateDoggo))]
    [AllowAnonymous]
    public async Task> RateDoggo(
    Guid id, [FromBody] DoggoRateDto rateDto)
    {
    if (rateDto == null)
    {
    return BadRequest();
    }
    DoggoEntity? existingEntity = _repository.GetSingle(id);
    existingEntity.RatingCount = existingEntity.RatingCount + 1;
    existingEntity.RatingSum = existingEntity.RatingSum + rateDto.Value;
    _repository.Update(existingEntity);
    if (!_repository.Save())
    {
    throw new Exception("Updating an item failed on save.");
    }
    DoggoDto dto = _mapper.Map(existingEntity);
    await _hubContext.Clients.All.SendAsync("DoggoRated", dto);
    return Ok(dto);
    }
    / ... /
    42
    43
    await _hubContext.Clients.All.SendAsync("DoggoAdded", dto);
    44
    45
    return CreatedAtRoute(nameof(GetSingleDoggo),
    46
    new { id = newItem?.Id }, dto);
    47
    }
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    }
    79

    View Slide

  12. namespace DoggoApi.Controllers
    {
    [ApiController]
    [Route("api/[controller]")]
    [Authorize("access:api")]
    public class DoggosController : ControllerBase
    {
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    [Authorize("access:api")]
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpGet(Name = nameof(GetAllDoggos))]
    [AllowAnonymous]
    public ActionResult GetAllDoggos()
    {
    List doggos = _repository.GetAll().ToList();
    return Ok(_mapper.Map(doggos));
    }
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpGet]
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    public ActionResult GetSingleDoggo(Guid id)
    {
    DoggoEntity? entity = _repository.GetSingle(id);
    if (entity == null)
    {
    return NotFound();
    }
    DoggoDto item = _mapper.Map(entity);
    return Ok(item);
    }
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    [HttpPost(Name = nameof(AddDoggo))]
    public async Task> AddDoggo(
    [FromBody] DoggoCreateDto createDto)
    {
    if (createDto == null)
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    33
    34
    35
    36
    37
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    namespace DoggoApi.Controllers
    1
    {
    2
    [ApiController]
    3
    [Route("api/[controller]")]
    4
    [Authorize("access:api")]
    5
    public class DoggosController : ControllerBase
    6
    {
    7
    [HttpGet(Name = nameof(GetAllDoggos))]
    8
    [AllowAnonymous]
    9
    public ActionResult GetAllDoggos()
    10
    {
    11
    List doggos = _repository.GetAll().ToList();
    12
    13
    return Ok(_mapper.Map(doggos));
    14
    }
    15
    16
    [HttpGet]
    17
    [Route("{id:guid}", Name = nameof(GetSingleDoggo))]
    18
    public ActionResult GetSingleDoggo(Guid id)
    19
    {
    20
    DoggoEntity? entity = _repository.GetSingle(id);
    21
    22
    if (entity == null)
    23
    {
    24
    return NotFound();
    25
    }
    26
    27
    DoggoDto item = _mapper.Map(entity);
    28
    29
    return Ok(item);
    30
    }
    31
    32
    [HttpPost(Name = nameof(AddDoggo))]
    33
    public async Task> AddDoggo(
    34
    [FromBody] DoggoCreateDto createDto)
    35
    {
    36
    if (createDto == null)
    37
    await _hubContext.Clients.All.SendAsync("DoggoRated", dto);
    / ... /
    42
    43
    await _hubContext.Clients.All.SendAsync("DoggoAdded", dto);
    44
    45
    return CreatedAtRoute(nameof(GetSingleDoggo),
    46
    new { id = newItem?.Id }, dto);
    47
    }
    48
    49
    [HttpPut]
    50
    [Route("rate/{id:guid}", Name = nameof(RateDoggo))]
    51
    [AllowAnonymous]
    52
    public async Task> RateDoggo(
    53
    Guid id, [FromBody] DoggoRateDto rateDto)
    54
    {
    55
    if (rateDto == null)
    56
    {
    57
    return BadRequest();
    58
    }
    59
    60
    DoggoEntity? existingEntity = _repository.GetSingle(id);
    61
    62
    existingEntity.RatingCount = existingEntity.RatingCount + 1;
    63
    existingEntity.RatingSum = existingEntity.RatingSum + rateDto.Value;
    64
    65
    _repository.Update(existingEntity);
    66
    67
    if (!_repository.Save())
    68
    {
    69
    throw new Exception("Updating an item failed on save.");
    70
    }
    71
    72
    DoggoDto dto = _mapper.Map(existingEntity);
    73
    74
    75
    76
    return Ok(dto);
    77
    }
    78
    }
    79

    View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. View Slide

  21. View Slide

  22. View Slide

  23. View Slide

  24. View Slide

  25. View Slide

  26. View Slide

  27. View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. View Slide

  32. View Slide

  33. View Slide

  34. View Slide

  35. View Slide

  36. View Slide

  37. @FabianGosebrink

    View Slide

  38. https://github.com/FabianGosebrink/doggo-rate-app

    View Slide

  39. View Slide