public async Task <IActionResult> EditUnitOfMeasure([FromBody] UnitOfMeasureEditViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(this.ApiResponse <string>(null, "Empty payload", ApiResponseCodes.INVALID_REQUEST));
            }

            var result = await _unitOfMeasureService.EditUnitOfMeasure(viewModel, this.CurrentUser.UserId);


            if (result.Any())
            {
                return(base.ApiResponse <string>(null, result.Select(r => r.ErrorMessage).ToArray(),
                                                 ApiResponseCodes.INVALID_REQUEST, result.Count()));
            }
            return(this.ApiResponse <UnitOfMeasureEditViewModel>(viewModel, "successful.", ApiResponseCodes.OK));
        }
Exemplo n.º 2
0
        public async Task <List <ValidationResult> > EditUnitOfMeasure(UnitOfMeasureEditViewModel viewModel, Guid createdBy)
        {
            try
            {
                if (viewModel == null)
                {
                    throw new ArgumentNullException(nameof(viewModel));
                }
                var unitOfMeasure = await this.GetByIdAsync(Guid.Parse(viewModel.Id));

                if (unitOfMeasure == null)
                {
                    results.Add(new ValidationResult($"{viewModel.Id} not found"));
                    return(results);
                }


                unitOfMeasure.Symbol     = viewModel.Symbol;
                unitOfMeasure.Name       = viewModel.Name;
                unitOfMeasure.Decimals   = viewModel.Decimals;
                unitOfMeasure.ModifiedBy = createdBy;
                unitOfMeasure.ModifiedOn = DateTime.UtcNow;
                var createResult = await this.UpdateAsync(unitOfMeasure);

                if (createResult == 0)
                {
                    results.Add(new ValidationResult("Update Failed"));
                    return(results);
                }

                viewModel.Id = unitOfMeasure.Id.ToString();
                return(results);
            }
            catch (Exception ex)
            {
                results.Add(new ValidationResult(ex.Message));
                return(results);
            }
        }