public GenericCreatedResponseDto CreateComanda(CreateComandaRequestDto comandaDto) { List <ResponseGetMercaderiaById> listaMercaderias = new List <ResponseGetMercaderiaById>(); foreach (var item in comandaDto.Mercaderias) { ResponseGetMercaderiaById mercaderia = _mercaderiaService.GetById(item.ToString()); listaMercaderias.Add(mercaderia); } int total = Calcularpreciototal(listaMercaderias); var entity = new Comanda { ComandaId = new Guid(), FormaEntregaId = comandaDto.FormaEntrega, PrecioTotal = total, Fecha = new DateTime() }; _repository.Add(entity); foreach (ResponseGetMercaderiaById item in listaMercaderias) { RegistrarComandaMercaderia(item.MercaderiaId, entity.ComandaId); } return(new GenericCreatedResponseDto { Entity = "Comanda", Id = entity.ComandaId.ToString() }); }
public IActionResult Post(CreateComandaRequestDto comanda) { try { return(new JsonResult(_service.CreateComanda(comanda)) { StatusCode = 201 }); } catch (Exception e) { return(new JsonResult(BadRequest(e.Message))); } }