コード例 #1
0
 /// <summary>
 /// Creates the specified point system.
 /// </summary>
 /// <param name="pointSystem">The point system.</param>
 /// <param name="messageType">Type of the message.</param>
 /// <param name="reward">The reward.</param>
 /// <returns></returns>
 public static Entites.MessageTypeToPointSystem Create(Entites.PointSystem pointSystem,
                                                       Entites.MessageType messageType, float reward)
 {
     return
         (DAL.MessageTypeToPointSystem.Create(new Entites.MessageTypeToPointSystem(pointSystem, messageType,
                                                                                   reward)));
 }
コード例 #2
0
 /// <summary>
 /// Creates the specified message type.
 /// </summary>
 /// <param name="messageType">Type of the message.</param>
 /// <returns>The same message type with an updated ID.</returns>
 public static Entites.MessageType Create(Entites.MessageType messageType)
 {
     using (TerministratorContext context = new TerministratorContext(true))
     {
         messageType.MessageTypeId = context.MessageType.Add(messageType).MessageTypeId;
         context.SaveChanges();
         return(messageType);
     }
 }
コード例 #3
0
 /// <summary>
 /// Updates the name of the specified message type.
 /// </summary>
 /// <param name="messageType">Type of the message.</param>
 /// <returns>The same message type.</returns>
 public static Entites.MessageType Update(Entites.MessageType messageType)
 {
     using (TerministratorContext context = new TerministratorContext(true))
     {
         Entites.MessageType original = context.MessageType.Find(messageType.MessageTypeId);
         if (original != null)
         {
             original.Name = messageType.Name;
             context.SaveChanges();
         }
         return(original);
     }
 }
コード例 #4
0
        /// <summary>
        /// Reads the array for the SetAmounts function.
        /// </summary>
        /// <param name="amounts">The amounts.</param>
        /// <param name="array">The array.</param>
        /// <returns></returns>
        private static string ReadArray(string[] amounts, out List <Tuple <string, float> > array)
        {
            array = new List <Tuple <string, float> >();

            foreach (string amount in amounts)
            {
                string[] splited = amount.Split(new[] { '-' }, 2);
                if (!float.TryParse(splited[0], out float reward))
                {
                    return($"Is \"{splited[0]}\" supposed to be a number?");
                }

                if (splited.Length == 1)
                {
                    if (array.Exists(x => x.Item1.Equals(UniqueOthers)))
                    {
                        return("You can only have one default value.");
                    }
                    array.Add(new Tuple <string, float>(UniqueOthers, reward));
                    continue;
                }

                if (array.Exists(x => x.Item1.Equals(splited[1])))
                {
                    return($"You have the element \"{splited[1]}\" more than once.");
                }

                Entites.MessageType messageType = MessageType.Get(splited[1]);
                if (messageType == null)
                {
                    return
                        ($"The message type \"{splited[1]}\" is not recognized. It can only be one of the followings: {MessageType.ToString()}");
                }

                array.Add(new Tuple <string, float>(UniqueOthers, reward));
            }

            return(null);
        }