Ejemplo n.º 1
0
        public JsonResult Post([FromBody] VesselViewModel vm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newVessel = vm.ToEntity();
                    _logger.LogInformation("Attempting to save a new Vessel");

                    _repository.Add(newVessel);

                    _unitOfWork.Commit();

                    Response.StatusCode = (int)HttpStatusCode.Created;
                    return(Json(VesselViewModel.FromEntity(newVessel)));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to save Vessel", ex);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Failed to save Vessel"));
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(new { Message = "Failed", ModelState = ModelState }));
        }
Ejemplo n.º 2
0
        public override JsonResult Get(int id)
        {
            try
            {
                var Ve   = _repository.GetSingle(id);
                var VeVm = VesselViewModel.FromEntity(Ve);

                if (VeVm == null)
                {
                    return(Json(null));
                }

                return(Json(VeVm));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to get Vessel", ex);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Failed to get Vessel"));
            }
        }
Ejemplo n.º 3
0
        public override JsonResult Get()
        {
            try
            {
                var Vessels = _repository.GetAll();

                var VesselsVm = Vessels.Select(x => VesselViewModel.FromEntity(x));

                if (VesselsVm == null)
                {
                    return(Json(null));
                }
                return(Json(VesselsVm));

                //return new string[] { "value1", "value2" };
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to get Vessels", ex);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Failed to get Vessels"));
            }
        }