Esempio n. 1
0
 public async Task <IActionResult> Change([FromBody] AttrCategoryChangeRequest request)
 {
     try
     {
         AttrCategoryAddOrChangeResponse response = new AttrCategoryAddOrChangeResponse();
         var results = AttrCategoryChangeRequestValidator.ValidateModel(request);
         if (results.IsValid)
         {
             results = AttrCategoryModelAddModelValidator.ValidateModel(request.AttrCategory);
             if (results.IsValid)
             {
                 response = await _attrCategoryAppService.AttrCategoryChange(request);
             }
             else
             {
                 response.SetFail(results.Errors.Select(p => p.ToString()));
             }
         }
         else
         {
             response.SetFail(results.Errors.Select(p => p.ToString()));
         }
         return(Json(response));
     }
     catch (Exception e)
     {
         _logger.LogError(e, Common.Common.GetMethodName(), request);
         throw;
     }
 }
        public async Task <AttrCategoryAddOrChangeResponse> AttrCategoryChange(AttrCategoryChangeRequest request)
        {
            AttrCategoryAddOrChangeResponse response = new AttrCategoryAddOrChangeResponse();

            try
            {
                var command = request.AttrCategory.ToChangeCommand();
                var result  = await _attrCategoryService.SendCommand(command);

                if (result.IsSucess)
                {
                    response.SetSucess();
                }
                else
                {
                    response.SetFail(result.Message);
                }
            }
            catch (Exception e)
            {
                response.SetFail(e);
                _logger.LogError(e, e.Message, request);
            }
            return(response);
        }