public Guid CreateNew(LoadFileModel model) { if (!model.FileName.ToLowerInvariant().EndsWith(".xml")) { model.FileName += ".xml"; } var user = _userSvc.CurrentUser(); Repos.File file = _files.GetByIdUserAndLabel(user.Id, model.FileName); var encriptionKey = model.FileKey; var crys = new CryptoService(); var empty = crys.Empty; var root = crys.Initialize(empty); var strData = crys.Save(); var encrypted = Encoding.UTF8.GetBytes(_crypt.Encrypt(strData, encriptionKey)); if (file == null) { file = new Repos.File { Id = Guid.NewGuid(), Label = model.FileLabel, Name = model.FileName, UserId = user.Id, Content = encrypted }; _files.Add(file); } else { file.Content = encrypted; _files.Update(file); } _attach.DeleteFile(file.Id); foreach (var singleFile in root.Attachments) { //_attach.DeleteFile(Guid.Parse(singleFile.Id)); var toAdd = new Attach { Id = Guid.Parse(singleFile.Id), UserId = user.Id, FileId = file.Id, Name = file.Name, Data = singleFile.Data }; _attach.Add(toAdd); } return(file.Id); }
public void Delete(String id) { User current = _login.CurrentUser(); if (!current.IsAdmin || id == current.Id.ToString()) { throw new Exception(); } foreach (var file in _files.GetAllByUser(current.Id).ToList()) { _files.Delete(file.Id); } foreach (var attach in _attach.GetAllByUser(current.Id).ToList()) { _attach.DeleteFile(attach.Id); } _users.Delete(Guid.Parse(id)); }