Advertisement
Guest User

TransBeispiel

a guest
Aug 16th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.13 KB | None | 0 0
  1. namespace VisSolutions.Commands
  2. {
  3.     using System;
  4.     using System.ComponentModel.Composition;
  5.     using System.Linq;
  6.     using System.Threading.Tasks;
  7.  
  8.     using Caliburn.Micro;
  9.  
  10.     using Combyte.Practices;
  11.     using Combyte.Practices.ExtensionMethods;
  12.     using Combyte.Practices.Logging;
  13.     using Combyte.VisSolutions.Core.Extensions;
  14.     using Combyte.VisSolutions.Core.Services;
  15.  
  16.     using VisSolutions.Core;
  17.     using VisSolutions.Core.UI;
  18.     using VisSolutions.Model;
  19.  
  20.     [Export(typeof(RemoveCurrentVersion))]
  21.     [Export(typeof(IVisCommand))]
  22.     [PartCreationPolicy(CreationPolicy.NonShared)]
  23.     public class RemoveCurrentVersion : CommandBase, IVisCommand
  24.     {
  25.         private static readonly ILogger log = VisLogManager.GetLog(typeof(ShowDetails));
  26.         private readonly IWindowManager windowManager;
  27.  
  28.         private readonly IVisMessageBoxFactory messageBoxFactory;
  29.  
  30.         private enum Trans
  31.         {
  32.             NurEineVersionVorhanden,
  33.             DokumentIstGeöffnet,
  34.             Bestätigung,
  35.             AktuelleVersionWirdGelöscht
  36.         }
  37.  
  38.         protected override object[] Translations => Vis.App.Resolve<IEnumService>().GetValues(typeof(Trans));
  39.  
  40.         [ImportingConstructor]
  41.         public RemoveCurrentVersion(IVisContext visContext, IWindowManager windowManager, IVisMessageBoxFactory messageBoxFactory)
  42.             : base(visContext)
  43.         {
  44.             this.windowManager = windowManager;
  45.             this.messageBoxFactory = messageBoxFactory;
  46.             this.ActionKey = "RemoveCurrentVersion";
  47.         }
  48.  
  49.         public override async Task<VisResult> Execute(VisTaskState vts)
  50.         {
  51.             var dataContext = this.Dialog.DialogProperties.DataContext;
  52.             if (dataContext.VisitenKarten.Count <= 1)
  53.             {
  54.                 this.VisResult.AddError(this.TL(Trans.NurEineVersionVorhanden));
  55.                 return this.VisResult.AsCanceled();
  56.  
  57.             }
  58.  
  59.             var docVersionMe =  dataContext.VisitenKarten.First().MasterEntity;
  60.             var docMe = (IMasterEntityDocument)await docVersionMe.GetFieldValueAsync(Entities.DocVersion.DokMasterEntity);
  61.             await docMe.LoadAsync();
  62.             var geöffnetVon = docMe.GetFieldValue(Entities.DokumentBase.IstGeöffnetVon);
  63.             if (!geöffnetVon.IsNullOrWhiteSpace())
  64.             {
  65.                 this.VisResult.AddError(this.TL(Trans.DokumentIstGeöffnet));
  66.                 return this.VisResult.AsCanceled();
  67.             }
  68.  
  69.             var response =
  70.                 await
  71.                     this.messageBoxFactory.ShowMessageBoxAsync(
  72.                         this.TL(Trans.Bestätigung),
  73.                         this.TL(Trans.AktuelleVersionWirdGelöscht),
  74.                         MessageType.Warning,
  75.                         this.Dialog,
  76.                         VisMessageBoxCommands.YesNo);
  77.  
  78.             if (response.VisCommand.ActionKey != AK.Ok)
  79.             {
  80.                 return this.VisResult.AsCanceled();
  81.             }
  82.  
  83.             var visDocAktuell = docMe.GetDocument();
  84.             var oldDocDb = visDocAktuell.DokumentDb;
  85.             oldDocDb.Delete();
  86.             visDocAktuell.Version = -visDocAktuell.Version;
  87.             visDocAktuell.Persisted = false;
  88.  
  89.             var df = (IVisDatenFeldDokument) docMe.Felder[Entities.DokumentBase.BLOB.EntityFieldId];
  90.  
  91.             var eList = df.Save();
  92.             eList.AddUnique(oldDocDb);
  93.             await this.VisContext.VisRepository.SaveAsync(eList);
  94.             var neueAktuelleVersion = await df.GetValueAsync(true);
  95.  
  96.             docMe.SetFieldValue(Entities.DokumentBase.Dateigrösse, neueAktuelleVersion.Size);
  97.             docMe.SetFieldValue(Entities.DokumentBase.LastModified, neueAktuelleVersion.MutiertAm);
  98.  
  99.             await docMe.UpdateCacheAsync();
  100.             eList = await docMe.PrepareSave(true, Guid.NewGuid());
  101.             await this.VisContext.VisRepository.SaveAsync(eList);
  102.  
  103.             var vk = dataContext.VisitenKarten.First();
  104.             dataContext.VisitenKarten.Remove(vk);
  105.             dataContext.VisitenKarten.Add(vk);
  106.  
  107.  
  108.             return this.VisResult;
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement