public MetadataEntity UserEdit(ref MetadataEntity entityOriginal, MetadataEntity entity, HttpContext context) { bool rename = false; bool changed = false; foreach (PropertyInfo property in entityOriginal.GetType().GetProperties()) { var origValue = property.GetValue(entityOriginal); var newValue = property.GetValue(entity); if (origValue != newValue) { switch (property.Name) { case "Name": changed = true; rename = true; entityOriginal.Name = entity.Name; break; case "Version": changed = true; rename = true; entityOriginal.Version = entity.Version; break; case "Extension": changed = true; rename = true; entityOriginal.Extension = entity.Extension; break; case "BuisnessArea": changed = true; entityOriginal.BuisnessArea = entity.BuisnessArea; break; case "Metadata": changed = true; entityOriginal.Metadata = entity.Metadata; break; default: break; //throw new Exception("Unable to Change this Property via this API Call"); } } } if (changed) { entityOriginal.LastUpdate.Update(context.User.Identity.Name); Touch(ref entityOriginal); } if (rename) { _documentRepository.RenameFileAsync(entityOriginal, entityOriginal).RunSynchronously(); } return(entityOriginal); }
public void AddNew(ref MetadataEntity entity, string user) { var timenow = DateTime.UtcNow; foreach (PropertyInfo property in entity.GetType().GetProperties()) { switch (property.Name) { case "Versions": entity.Versions = new List <DocumentVersionEntity>(); break; case "LastViewed": entity.LastViewed = timenow; break; case "LastUpdate": entity.LastUpdate.ServerUpdate(user, timenow); break; case "Created": entity.Created.ServerUpdate(user, timenow); break; case "Archive": entity.Archive = new ArchiveState(); break; case "MD5Hash": entity.MD5Hash = string.Empty; break; case "Version": entity.Version = 1; break; case "Name": if (string.IsNullOrWhiteSpace(entity.Name)) { throw new ArgumentNullException("Name"); } break; case "StorName": if (string.IsNullOrWhiteSpace(entity.StorName)) { throw new ArgumentNullException("StorName"); } break; case "Extension": if (string.IsNullOrWhiteSpace(entity.Extension)) { throw new ArgumentNullException("Extension"); } break; case "BuisnessArea": if (string.IsNullOrWhiteSpace(entity.BuisnessArea)) { throw new ArgumentNullException("BuisnessArea"); } break; case "Id": if (property != null) { throw new ArgumentException("Id can not be set on client", "Id"); } break; default: break; } } _context.MetadataEntities.Add(entity); }