Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new Version Info entity.
        /// </summary>
        /// <param name="component">The name of the component.</param>
        /// <param name="version">The version of the component.</param>
        /// <returns>A <see cref="ManagerResponse"/> object.</returns>
        public ManagerResponse Add(string component, string version)
        {
            // Validate parameters
            if (String.IsNullOrWhiteSpace(component))
            {
                return ManagerResponse.InvalidData;
            }

            if (String.IsNullOrWhiteSpace(version))
            {
                return ManagerResponse.InvalidData;
            }

            var sqlScriptVersionInfo = new SqlScriptVersionInfo()
            {
                Component = component,
                Version = version,
            };

            ManagerResponse response;

            using (var context = new Entities(_connectionString))
            {
                context.SqlScriptVersionInfos.AddObject(sqlScriptVersionInfo as SqlScriptVersionInfo);
                response = context.SaveChanges() == 1 ? ManagerResponse.Success : ManagerResponse.UnknownFailure;
            }

            return response;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the specified <see cref="IVersionInfo"/> entity.
        /// </summary>
        /// <param name="versionInfo">The <see cref="IVersionInfo"/> entity to update.</param>
        /// <returns>A <see cref="ManagerResponse"/> object.</returns>
        public ManagerResponse Update(IVersionInfo versionInfo)
        {
            // Validate parameters
            if (versionInfo == null)
            {
                return ManagerResponse.MissingData;
            }

            if (String.IsNullOrWhiteSpace(versionInfo.Component))
            {
                return ManagerResponse.InvalidData;
            }

            if (String.IsNullOrWhiteSpace(versionInfo.Version))
            {
                return ManagerResponse.InvalidData;
            }

            ManagerResponse response;

            using (var context = new Entities(_connectionString))
            {
                context.SqlScriptVersionInfos.Attach(versionInfo as SqlScriptVersionInfo);
                context.ObjectStateManager.ChangeObjectState(versionInfo, EntityState.Modified);
                response = context.SaveChanges() == 1 ? ManagerResponse.Success : ManagerResponse.UnknownFailure;
            }

            return response;
        }