示例#1
0
 // PATCH tables/Domain/48D68C86-6EA6-4C25-AA33-223FC9A27959
 public Task <Domain> PatchDomain(string id, Delta <DomainRequest> patch)
 {
     try
     {
         // patch Mappers does not work for Patch.Itws a limitation.
         ValidationUtilities.ValidateEditDomainRequest(patch.GetEntity(), patch.GetChangedPropertyNames().ToList());
         string         currentUserEmail = HttpUtilities.GetUserNameFromToken(this.Request);
         Delta <Domain> deltaDest        = new Delta <Domain>();
         //Domain dbObject = context.Domains.FirstOrDefault(a => a.Id == id);
         //Mapper.Initialize(cfg => cfg.CreateMap<DomainRequest, Domain>()
         // .ForMember(i => i.ModifiedBy, j => j.UseValue(currentUserEmail))
         // .ForMember(i => i.UpdatedAt, j => j.UseValue(DateTimeOffset.UtcNow))
         //);
         //var domainMap = Mapper.Map<DomainRequest, Domain>(patch.GetEntity(), dbObject);
         //deltaDest.Put(domainMap);
         //patch.
         foreach (var item in patch.GetChangedPropertyNames())
         {
             object result;
             patch.TryGetPropertyValue(item, out result);
             bool bResult;
             if (bool.TryParse(result.ToString(), out bResult))
             {
                 deltaDest.TrySetPropertyValue(item, bResult);
             }
             else
             {
                 deltaDest.TrySetPropertyValue(item, result);
             }
         }
         deltaDest.TrySetPropertyValue("ModifiedBy", currentUserEmail);
         deltaDest.TrySetPropertyValue("UpdatedAt", DateTimeOffset.UtcNow);
         return(UpdateAsync(id, deltaDest));
     }
     catch (HttpResponseException ex)
     {
         LGSELogger.Error(ex);
         throw ex;
     }
 }