ActivEarth.DAO.UserStatisticDAO.CreateNewStatisticForUser C# (CSharp) Метод

CreateNewStatisticForUser() публичный статический Метод

Saves a user statistic as a new entry in the DB.
public static CreateNewStatisticForUser ( int userId, Statistic statType, float val ) : int
userId int User to create stat for.
statType Statistic Statistic type to create.
val float Value of the statistic.
Результат int
        public static int CreateNewStatisticForUser(int userId, Statistic statType, float val)
        {
            try
            {
                int id;

                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    var data = new ActivEarthDataProvidersDataContext(connection);
                    var statisticData = new UserStatisticDataProvider
                    {
                        user_id = userId,
                        value = val,
                        statistic_type = (byte)statType
                    };

                    data.UserStatisticDataProviders.InsertOnSubmit(statisticData);
                    data.SubmitChanges();

                    id = statisticData.id;
                }

                return id;
            }
            catch (Exception)
            {
                return 0;
            }
        }