Esempio n. 1
0
        public async Task <ActionResult <UnitDto> > Create(UnitDto unitDto)
        {
            var unit          = _mapper.Map <Unit>(unitDto);
            var validationRes = _validator.Validate(unit);

            if (!validationRes.IsValid)
            {
                return(BadRequest(new { errors = validationRes.Errors }));
            }
            var res = await _unitRepository.Create(unit);

            return(CreatedAtAction(nameof(Get), new { Id = unit.Id }, unit));
        }
Esempio n. 2
0
        public void SaveUnit()
        {
            UnitModel currentUnit = new UnitModel();

            CollectUnitDetails(currentUnit);
            UnitValidator    validator = new UnitValidator();
            ValidationResult result    = validator.Validate(currentUnit);

            if (result.IsValid == false)
            {
                string errorMessage = (String.Join(Environment.NewLine + "   • ",
                                                   result.Errors.Select(error => error.ErrorMessage)));
                universalHelper.MessageDialog("Saving of data failed!", "   • " + errorMessage);
                return;
            }
            else
            {
                uHelper.SaveItem(currentUnit);
                ClearUnitFields();
            }
        }