/// <summary>
        ///  Checks the right for the update process and updates the dataset and
        /// </summary>
        /// <param name="datasetDto">dataset</param>
        /// <param name="userId">userid</param>
        /// <returns>the updated dataset</returns>
        public DatasetDto Update(DatasetDto datasetDto, int userId)
        {
            ValidateDataset(datasetDto);

            Dataset result = null;

            if (datasetDto.Id > 0)
            {
                Dataset ds = _datasetRepository.GetById(datasetDto.Id);
                ds.Data     = datasetDto.Json;
                ds.Flags    = datasetDto.Flags;
                ds.Name     = datasetDto.Name;
                ds.Modified = DateTime.Now;
                if (ds.UserId != userId)
                {
                    throw new Exception("No permission to update this dataset.");
                }

                _datasetRepository.DataContext.Commit();
                result = ds;
            }
            else
            {
                Dataset ds = new Dataset()
                {
                    Id       = 0,
                    Name     = datasetDto.Name,
                    Flags    = datasetDto.Flags,
                    Data     = datasetDto.Json,
                    UserId   = userId,
                    Created  = DateTime.Now,
                    Modified = DateTime.Now
                };
                _datasetRepository.Add(ds);
                _datasetRepository.DataContext.Commit();
                result = ds;
            }

            return(DatasetMapper.ToDto(result));
        }