public void AttachmentChunkingComplete() { var fileName = Request["qqfilename"]; if (string.IsNullOrEmpty(fileName) || fileName == Path.DirectorySeparatorChar.ToString()) { throw new HttpException(); } var attachmentGuid = Request["attachmentGuid"]; if (string.IsNullOrEmpty(attachmentGuid)) { throw new HttpException(); } var computerId = Request["computerId"]; var assetId = Request["assetId"]; if (assetId == null && computerId == null) { throw new HttpException(); } var userId = Convert.ToInt32(((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == "user_id") .Select(c => c.Value).SingleOrDefault()); var userName = new ServiceUser().GetUserName(userId); var attachment = new EntityAttachment(); attachment.AttachmentTime = DateTime.Now; attachment.DirectoryGuid = attachmentGuid; attachment.Name = fileName; attachment.UserName = userName; var result = new ServiceAttachment().Add(attachment); if (!result.Success) { throw new HttpException(); } if (assetId != null) { var asset = new EntityAssetAttachment(); asset.AssetId = Convert.ToInt32(assetId); asset.AttachmentId = attachment.Id; result = new ServiceAssetAttachment().Add(asset); if (!result.Success) { throw new HttpException(); } } if (computerId != null) { var computer = new EntityComputerAttachment(); computer.ComputerId = Convert.ToInt32(computerId); computer.AttachmentId = attachment.Id; result = new ServiceComputerAttachment().Add(computer); if (!result.Success) { throw new HttpException(); } } }
private string SaveAs(string type) { var filePath = Path.Combine(_upload.DestinationDirectory, _upload.Filename); using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { try { using (var file = new FileStream(filePath, FileMode.Create)) _upload.InputStream.CopyTo(file); } catch (Exception ex) { return(ex.Message); } if (type.Equals("module")) { var uploadedFile = new EntityUploadedFile(); uploadedFile.Name = _upload.Filename; uploadedFile.Guid = _upload.ModuleGuid; uploadedFile.Hash = Utility.GetFileHash(filePath); var result = new ServiceUploadedFile().AddFile(uploadedFile); if (!result.Success) { try { File.Delete(filePath); } catch { //ignored } return("Could Not Update Database"); } } else if (type.Equals("attachment")) { var attachment = new EntityAttachment(); attachment.AttachmentTime = DateTime.Now; attachment.DirectoryGuid = _upload.AttachmentGuid; attachment.Name = _upload.Filename; attachment.UserName = _upload.Username; var result = new ServiceAttachment().Add(attachment); if (!result.Success) { throw new HttpException(); } if (_upload.AssetId != null) { var asset = new EntityAssetAttachment(); asset.AssetId = Convert.ToInt32(_upload.AssetId); asset.AttachmentId = attachment.Id; result = new ServiceAssetAttachment().Add(asset); if (!result.Success) { throw new HttpException(); } } if (_upload.ComputerId != null) { var computer = new EntityComputerAttachment(); computer.ComputerId = Convert.ToInt32(_upload.ComputerId); computer.AttachmentId = attachment.Id; result = new ServiceComputerAttachment().Add(computer); if (!result.Success) { throw new HttpException(); } } } } else { return("Could Not Reach Storage Path"); } } return(null); }