Exemple #1
0
 protected static async Task SaveChanges(SocialGamificationAssetContext _context, bool isAsync = false)
 {
     try
     {
         if (isAsync)
         {
             await _context.SaveChangesAsync();
         }
         else
         {
             _context.SaveChanges();
         }
     }
     catch (DbUpdateException e)
     {
         throw e;
     }
 }
        /// <summary>
        ///     Asynchronously save data
        /// </summary>
        /// <returns>
        ///     <para>
        ///         ErrorContentResult if
        ///         <see cref="System.Data.Entity.Infrastructure.DbUpdateException" />
        ///     </para>
        ///     <para>exception occurs</para>
        /// </returns>
        public static async Task <ContentResult> SaveChanges(
            SocialGamificationAssetContext _context,
            bool isAsync = false)
        {
            try
            {
                if (isAsync)
                {
                    await _context.SaveChangesAsync();
                }
                else
                {
                    _context.SaveChanges();
                }
            }
            catch (DbUpdateException e)
            {
                return(HttpResponseHelper.ErrorContentResult(
                           GetExceptionString(e),
                           StatusCodes.Status500InternalServerError));
            }

            return(null);
        }
        /// <summary>
        ///     Asynchronously save data
        /// </summary>
        /// <returns>
        ///     <para>
        ///         ErrorContentResult if
        ///         <see cref="System.Data.Entity.Infrastructure.DbUpdateException" />
        ///     </para>
        ///     <para>exception occurs</para>
        /// </returns>
        public static async Task<ContentResult> SaveChanges(
            SocialGamificationAssetContext _context,
            bool isAsync = false)
        {
            try
            {
                if (isAsync)
                {
                    await _context.SaveChangesAsync();
                }
                else
                {
                    _context.SaveChanges();
                }
            }
            catch (DbUpdateException e)
            {
                return HttpResponseHelper.ErrorContentResult(
                    GetExceptionString(e),
                    StatusCodes.Status500InternalServerError);
            }

            return null;
        }
 protected static async Task SaveChanges(SocialGamificationAssetContext _context, bool isAsync = false)
 {
     try
     {
         if (isAsync)
         {
             await _context.SaveChangesAsync();
         }
         else
         {
             _context.SaveChanges();
         }
     }
     catch (DbUpdateException e)
     {
         throw e;
     }
 }