ActivEarth.DAO.ChallengeDAO.CreateNewChallenge C# (CSharp) Метод

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

Saves a challenge as a new entry in the DB.
public static CreateNewChallenge ( Challenge challenge ) : int
challenge ActivEarth.Objects.Competition.Challenges.Challenge Challenge object to add to the DB.
Результат int
        public static int CreateNewChallenge(Challenge challenge)
        {
            try
            {
                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    var data = new ActivEarthDataProvidersDataContext(connection);
                    var challengeData = new ChallengeDataProvider
                        {
                            name = challenge.Name,
                            description = challenge.Description,
                            reward = challenge.Reward,
                            requirement = challenge.Requirement,
                            persistent = challenge.IsPersistent,
                            end_time = challenge.EndTime,
                            duration_days = challenge.Duration.Days,
                            statistic = (byte)challenge.StatisticBinding,
                            active = challenge.IsActive,
                            image_path = challenge.ImagePath
                        };
                    data.ChallengeDataProviders.InsertOnSubmit(challengeData);
                    data.SubmitChanges();
                    return challengeData.id;
                }
            }
            catch (Exception)
            {
                return 0;
            }
        }