Esempio n. 1
0
        public JsonResult Post([FromBody] MCIDataViewModel vm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newMCIData = vm.ToEntity();
                    _logger.LogInformation("Attempting to save a new MCIData");

                    _repository.Add(newMCIData);

                    _unitOfWork.Commit();

                    Response.StatusCode = (int)HttpStatusCode.Created;
                    return(Json(MCIDataViewModel.FromEntity(newMCIData)));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to save MCIData", ex);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Failed to save MCIData"));
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(new { Message = "Failed", ModelState = ModelState }));
        }
Esempio n. 2
0
        public override JsonResult Get(int id)
        {
            try
            {
                var Md   = _repository.GetSingle(id);
                var MdVm = MCIDataViewModel.FromEntity(Md);

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

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

                var MCIDatasVm = MCIDatas.Select(x => MCIDataViewModel.FromEntity(x));

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

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