Exemple #1
0
        public List <UnitConversionRules> Patch(UnitConversionRulesBatch request)
        {
            if (true != request?.Any())
            {
                throw new HttpError(HttpStatusCode.NotFound, "Request cannot be empty.");
            }

            var ret      = new List <UnitConversionRules>();
            var errors   = new List <ResponseError>();
            var errorMap = new Dictionary <string, string>();
            var i        = 0;

            request.ForEach(dto =>
            {
                try
                {
                    var obj = Patch(dto) as UnitConversionRules;
                    ret.Add(obj);
                    errorMap[$"{i}"] = $"true";
                }
                catch (Exception ex)
                {
                    errorMap[$"{i}"] = $"false";
                    errors.Add(new ResponseError()
                    {
                        Message   = $"{ex.Message}{Environment.NewLine}{ex.InnerException?.Message}",
                        ErrorCode = $"{i}"
                    });
                }
                i += 1;
            });
            base.Response.AddHeader("X-AutoBatch-Completed", $"{ret.Count} succeeded");
            if (errors.Any())
            {
                throw new HttpError(HttpStatusCode.BadRequest, $"{errors.Count} failed in batch")
                      {
                          Response = new ErrorResponse()
                          {
                              ResponseStatus = new ResponseStatus
                              {
                                  ErrorCode = nameof(HttpError),
                                  Meta      = errorMap,
                                  Message   = "Incomplete request",
                                  Errors    = errors
                              }
                          }
                      };
            }
            return(ret);
        }
Exemple #2
0
 public List <UnitConversionRules> Put(UnitConversionRulesBatch request)
 {
     return(Patch(request));
 }