Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. public Task<Mapping> EditMapping(Mapping mapping)
  2.         {
  3.             var definitions = sites
  4.                 .FirstOrDefault(site => site.Id == mapping.SiteId)
  5.                 .MappingDefinitions;
  6.  
  7.             var modifiedDefinitions = definitions.Select(definition => {
  8.                     return definition.Mappings
  9.                     .Select(x => x.Id == mapping.Id ? mapping : x)
  10.                     .ToList();
  11.                 })
  12.                 .ToList();
  13.                    
  14.  
  15.             var modifiedDefinitions = definitions.Aggregate(new List<MappingDefinition>(), (mappingDefinitions, definition) => {
  16.                 definition.Mappings = definition.Mappings
  17.                     .Select(x => x.Id == mapping.Id ? mapping : x)
  18.                     .ToList();
  19.  
  20.                 var exisitingDefinitions = mappingDefinitions;
  21.  
  22.                 exisitingDefinitions.Add(definition);
  23.  
  24.                 return exisitingDefinitions;
  25.             });
  26.  
  27.             // Please note. Stuff like this is only because we do not have a DB to store it on
  28.             // Our current data is a big long ass object
  29.             sites.FirstOrDefault(site => site.Id == mapping.SiteId).MappingDefinitions = modifiedDefinitions;
  30.  
  31.             return Task.FromResult(mapping);
  32.         }
  33.  
  34. public
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement