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

                    _repository.Add(newBerth);

                    _unitOfWork.Commit();

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

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

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

                var BerthsVm = Berths.Select(x => BerthViewModel.FromEntity(x));

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

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