Пример #1
0
        public async Task <IActionResult> Put(int key, string values)
        {
            var model = _uow.GetObjectByKey <Series>(key, true);

            if (model == null)
            {
                return(StatusCode(409, "Object not found"));
            }

            var viewModel = new SeriesViewModel {
                Pk_Serie   = model.Pk_Serie,
                Pk_Empresa = model.Pk_Empresa,
                Serie      = model.Serie,
                Folio      = model.Folio
            };

            var valuesDict = JsonConvert.DeserializeObject <IDictionary>(values);

            PopulateViewModel(viewModel, valuesDict);

            if (!TryValidateModel(viewModel))
            {
                return(BadRequest(GetFullErrorMessage(ModelState)));
            }

            CopyToModel(viewModel, model);

            await _uow.CommitChangesAsync();

            return(Ok());
        }
Пример #2
0
 private void CopyToModel(SeriesViewModel viewModel, Series model)
 {
     model.Pk_Serie   = viewModel.Pk_Serie;
     model.Pk_Empresa = viewModel.Pk_Empresa;
     model.Serie      = viewModel.Serie;
     model.Folio      = viewModel.Folio;
 }
Пример #3
0
        public async Task <IActionResult> Post(string values)
        {
            var model      = new Series(_uow);
            var viewModel  = new SeriesViewModel();
            var valuesDict = JsonConvert.DeserializeObject <IDictionary>(values);

            PopulateViewModel(viewModel, valuesDict);

            if (!TryValidateModel(viewModel))
            {
                return(BadRequest(GetFullErrorMessage(ModelState)));
            }

            CopyToModel(viewModel, model);

            await _uow.CommitChangesAsync();

            return(Json(model.Pk_Serie));
        }
Пример #4
0
 private void PopulateViewModel(SeriesViewModel viewModel, IDictionary values)
 {
     if (values.Contains(PK_SERIE))
     {
         viewModel.Pk_Serie = Convert.ToInt32(values[PK_SERIE]);
     }
     if (values.Contains(PK_EMPRESA))
     {
         viewModel.Pk_Empresa = Convert.ToInt32(values[PK_EMPRESA]);
     }
     if (values.Contains(SERIE))
     {
         viewModel.Serie = Convert.ToString(values[SERIE]);
     }
     if (values.Contains(FOLIO))
     {
         viewModel.Folio = Convert.ToInt32(values[FOLIO]);
     }
 }