/// <summary> /// Saves a challenge as a new entry in the DB. /// </summary> /// <param name="challenge">Challenge object to add to the DB.</param> /// <returns>ID of the created challenge on success, 0 on failure.</returns> 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; } }
partial void DeleteChallengeDataProvider(ChallengeDataProvider instance);
partial void UpdateChallengeDataProvider(ChallengeDataProvider instance);
partial void InsertChallengeDataProvider(ChallengeDataProvider instance);