This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<div class="starter-template"> | |
<h1>Bootstrap starter template</h1> | |
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public async Task<IActionResult> PostAsync([FromBody] SaveCategoryResource resource) | |
{ | |
if (!ModelState.IsValid) | |
return BadRequest(ModelState.GetErrorMessages()); | |
var category = _mapper.Map<SaveCategoryResource, Category>(resource); | |
var result = await _categoryService.SaveAsync(category); | |
if (!result.Success) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SuperMarketAPI.Domain.Services.Communication; | |
using SuperMarketAPI.Models; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
namespace SuperMarketAPI.Domain.Services | |
{ | |
public interface ICategoryService | |
{ | |
Task<IEnumerable<Category>> ListAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SuperMarketAPI.Models; | |
namespace SuperMarketAPI.Domain.Services.Communication | |
{ | |
public class SaveCategoryResponse : BaseResponse | |
{ | |
public Category Category { get; private set; } | |
private SaveCategoryResponse(bool success, string message, Category category) : base(success, message) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace SuperMarketAPI.Domain.Services.Communication | |
{ | |
public abstract class BaseResponse | |
{ | |
public bool Success { get; protected set; } | |
public string Message { get; protected set; } | |
public BaseResponse(bool success, string message) | |
{ | |
Success = success; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public async Task<IActionResult> PostAsync([FromBody] SaveCategoryResource resource) | |
{ | |
if (!ModelState.IsValid) | |
return BadRequest(ModelState.GetErrorMessages()); | |
var category = _mapper.Map<SaveCategoryResource, Category>(resource); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using AutoMapper; | |
using SuperMarketAPI.Models; | |
using SuperMarketAPI.Resources; | |
namespace SuperMarketAPI.Mapping | |
{ | |
public class ResourceToModelProfile : Profile | |
{ | |
public ResourceToModelProfile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Mvc.ModelBinding; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace SuperMarketAPI.Extention | |
{ | |
public static class ModelStateExtensions | |
{ | |
public static List<string> GetErrorMessages(this ModelStateDictionary dictionary) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public async Task<IActionResult> PostAsync([FromBody] SaveCategoryResource resource) | |
{ | |
if (!ModelState.IsValid) | |
return BadRequest(ModelState.GetErrorMessages()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel.DataAnnotations; | |
namespace SuperMarketAPI.Resources | |
{ | |
public class SaveCategoryResource | |
{ | |
[Required] | |
[MaxLength(30)] | |
public string Name { get; set; } | |
} |