Ejemplo n.º 1
0
        /// <summary>
        /// Add an achievement to the list of DJ achievements stored in the server.
        /// If the achievement is invalid, an error is returned.
        /// </summary>
        /// <param name="achievement">The achievement to add.</param>
        /// <param name="DJKey">The DJKey for the venue.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response DJAddAchievement(Achievement achievement, long DJKey)
        {
            int DJID = -1;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;

                // Convert the DJKey to a DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;

                foreach(AchievementSelect a in achievement.selectList)
                {
                    if (a.startDate.Year < 1754)
                    {
                        a.startDate = new DateTime(1900, 1, 1);
                    }
                }

                string sqlText;
                List<SqlCommand> cmds;
                r = AchievementParser.CreateAchievementSQL(achievement, DJID, out sqlText, out cmds);
                if (r.error)
                    return r;

                r = db.DJAddAchievement(DJID, achievement);
                if (r.error)
                    return r;

                achievement.ID = r.result;

                r = Common.EvaluateAchievement(DJID, achievement, db);
                if (r.error)
                    return r;

                r.message = achievement.ID.ToString();
                r.result = achievement.ID;
                return r;
            }
        }