예제 #1
0
        public int AddAward(Award award)
        {
            var elements = this.document
                .Root
                .Elements(TableName);

            int maxId = award.Id;

            if (award.Id == 0)
            {
                maxId = (!elements.Any()) ? 0 : elements.Max(t => (int)t.Attribute(FId));

                XElement awardElement = new XElement(
                    TableName,
                    new XAttribute(FId, ++maxId),
                    new XElement(FTitle, award.Title));

                this.document.Root.Add(awardElement);
            }
            else
            {
                elements = elements.Where(el => (int)el.Attribute(FId) == award.Id);

                if (!elements.Any())
                {
                    return 0;
                }

                elements.First().SetElementValue(FTitle, award.Title);
            }

            this.document.Save(this.pathAwardXml);

            return maxId;
        }
예제 #2
0
        public bool AddAward(Award award)
        {
            this.CheckAwardsValues(award);

            Stores.AwardStore.AddAward(award);

            return true;
        }
예제 #3
0
        public bool AddAward(Award award)
        {
            this.CheckAwardsValues(award);

            var awardNew = Stores.AwardStore.GetAwardByTitle(award.Title);

            if (awardNew != null)
            {
                throw new InvalidOperationException($"Award '{award.Title}' allready exests.");
            }

            Stores.AwardStore.AddAward(new Award(award.Title));

            return true;
        }
예제 #4
0
        public int AddAward(Award award)
        {
            var elements = this.document
                .Root
                .Elements(TableName);

            int maxId = (!elements.Any()) ? 0 : elements.Max(t => (int)t.Attribute(FId));

            XElement awardElement = new XElement(
                TableName,
                new XAttribute(FId, ++maxId),
                new XElement(FTitle, award.Title));

            this.document.Root.Add(awardElement);
            this.document.Save(this.pathAwardXml);

            return maxId;
        }
예제 #5
0
        private void CheckAwardsValues(Award award)
        {
            if (award == null)
            {
                throw new ArgumentException($"The Award mustn't be null.");
            }

            if (string.IsNullOrWhiteSpace(award.Title))
            {
                throw new ArgumentException($"The Title mustn't be empty.");
            }

            if (award.Title.Length > this.maxTitleLength)
            {
                throw new ArgumentException($"The Title mustn't be longer than {this.maxTitleLength}");
            }

            var matches = this.regAwardTitle.Matches(award.Title);

            if (matches.Count != 0)
            {
                StringBuilder strMatches = new StringBuilder(this.maxTitleLength);

                foreach (Match match in matches)
                {
                    strMatches.Append(match.Value);
                }

                throw new ArgumentException($"Characters '{strMatches.ToString()}' aren't correct for the Title.");
            }
        }