示例#1
0
        public async Task <ActionResult <TiqueteViewModel> > PostAsync(TiqueteInputModel tiqueteInput)
        {
            Tiquete tiquete  = MapearTiquete(tiqueteInput);
            var     response = _tiqueteService.Guardar(tiquete);

            if (response.Error)
            {
                ModelState.AddModelError("Guardar Tiquete", response.Mensaje);
                var problemDetails = new ValidationProblemDetails(ModelState)
                {
                    Status = StatusCodes.Status400BadRequest,
                };
                return(BadRequest(response.Mensaje));
            }
            var tiqueteViewModel = new TiqueteViewModel(response.Tiquete);
            await _hubContext.Clients.All.SendAsync("TiqueteRegistrado", tiqueteViewModel);

            return(Ok(tiqueteViewModel));
        }
示例#2
0
        public async Task <ActionResult <Tiquete> > PostTiquete(TiqueteViewModel request)
        {
            var tiquete = new Tiquete()
            {
                Id       = request.Id,
                Ruta     = request.RutaViewMode,
                Pasajero = request.ClienteViewModel,
                Cantidad = request.number,
                total    = request.number
            };

            _context.Tiquete.Add(tiquete);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (RutaExists(tiquete.Id))
                {
                    ModelState.AddModelError("Tiquete", "El codigo de  tiquete ya se necuentra registrado");
                    var problemDetails = new ValidationProblemDetails(ModelState)
                    {
                        Status = StatusCodes.Status400BadRequest,
                    };
                    return(BadRequest(problemDetails));
                }
                else
                {
                    ModelState.AddModelError("Tiquete", "Existe un problema con el tiquete");
                    var problemDetails = new ValidationProblemDetails(ModelState)
                    {
                        Status = StatusCodes.Status400BadRequest,
                    };
                    return(BadRequest(problemDetails));
                }
            }

            return(CreatedAtAction("GetRuta", new { id = Tiquete.Id }, tiquete));
        }