/// <summary> /// Updates the process. /// </summary> /// <param name="dto">The process DTO.</param> /// <param name="locDto">The process localization DTO.</param> /// <exception cref="System.ArgumentException">The input DTO is null.</exception> /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data.</exception> public void UpdateProcessWithLocalization(ProcessEditDto dto, ProcessLocalizationDto locDto) { if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); const string CommandText = @" UPDATE [dbo].[Processes] SET [LastUpdated] = @p_LastModifiedOn ,[SystemName] = @p_SystemName ,[BaseProcessId] = @p_BaseProcessId ,[IconId] = @p_IconId ,[ProcessOption] = @p_ProcessOption ,[IsStateEnabled] = @p_IsStateEnabled ,[DefaultStateId] = @p_DefaultStateId ,[AllowPaperclips] = @p_AllowPaperclips ,[ColorId] = @p_ColorId ,[InheritanceContext] = @p_inheritanceContext ,[ShowDerivedProcess] = @p_showDerivedProcess ,[SimpleProcess] = @p_simpleProcess ,[IsInactive] = @p_isInactive WHERE [Id] = @p_Id "; using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var connection = ctx.Connection; using (var command = new SqlCommand(CommandText, connection)) { command.Parameters.AddWithValue("@p_Id", dto.Id); command.Parameters.AddWithValue("@p_LastModifiedOn", DateTime.Now); ; command.Parameters.AddWithValue("@p_SystemName", dto.SystemName); if (dto.BaseProcessId.HasValue) command.Parameters.AddWithValue("@p_BaseProcessId", dto.BaseProcessId); else command.Parameters.AddWithValue("@p_BaseProcessId", DBNull.Value); command.Parameters.AddWithValue("@p_IconId", AdoHelper.NullCheck(dto.IconId)); command.Parameters.AddWithValue("@p_ColorId", AdoHelper.NullCheck(dto.ColorId)); command.Parameters.AddWithValue("@p_ProcessOption", dto.ProcessOption); command.Parameters.AddWithValue("@p_IsStateEnabled", dto.IsStateEnabled); command.Parameters.AddWithValue("@p_DefaultStateId", dto.DefaultStateId); command.Parameters.AddWithValue("@p_AllowPaperclips", dto.AllowPaperclips); command.Parameters.AddWithValue("@p_inheritanceContext", AdoHelper.NullCheck(dto.InheritanceContext)); command.Parameters.AddWithValue("@p_showDerivedProcess", dto.ShowDerivedProcess); command.Parameters.AddWithValue("@p_simpleProcess", dto.SimpleProcess); command.Parameters.AddWithValue("@p_isInactive", dto.IsInactive); using (var reader = new SafeDataReader(command.ExecuteReader())) if (reader.RecordsAffected == 0) throw new DBConcurrencyException(Resources.StaleDataException); } } UpdateProcessLocalization(locDto); }
/// <summary> /// Updates the localization for processes. /// </summary> /// <param name="dto">The localization dto.</param> /// <exception cref="System.ArgumentException"></exception> /// <exception cref="System.Data.DBConcurrencyException"></exception> public void UpdateProcessLocalization(ProcessLocalizationDto dto) { if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var connection = ctx.Connection; const string commandText = @" IF EXISTS ( SELECT * FROM [dbo].[ProcessLocalizations] WHERE [LocalizationId] = @p_localizationId and [ProcessId] = @p_processId) BEGIN UPDATE [dbo].[ProcessLocalizations] SET [LocalizationId] = @p_localizationId, [ProcessId] = @p_processId, [GuidId] = @p_guidId, [ProcessName] = @p_processName, [ProcessDescription] = @p_processDescription, [ProcessDocumentation] = @p_processDocumentation WHERE [LocalizationId] = @p_localizationId and [ProcessId] = @p_processId END ELSE INSERT INTO [dbo].[ProcessLocalizations] ( [LocalizationId], [ProcessId], [ProcessName], [ProcessDescription], [ProcessDocumentation] ) VALUES ( @p_localizationId, @p_processId, @p_processName, @p_processDescription, @p_processDocumentation)"; using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddWithValue("@p_localizationId", dto.LocalizationId); command.Parameters.AddWithValue("@p_processId", dto.ProcessId); command.Parameters.AddWithValue("@p_guidId", dto.GuidId); command.Parameters.AddWithValue("@p_processName", dto.Name); command.Parameters.AddWithValue("@p_processDescription", dto.Description); command.Parameters.AddWithValue("@p_processDocumentation", dto.Documentation); var rowsAffetcted = command.ExecuteNonQuery(); if (rowsAffetcted == 0) { throw new DBConcurrencyException(Resources.StaleDataException); } } } }