示例#1
0
        public Character Add(Character theCharacter)
        {
            if (theCharacter == null)
            {
                throw new ArgumentNullException(nameof(Character));
            }
            ;

            ObjectValidator.Validate(theCharacter);

            var existing = FindByName(theCharacter.Name);

            if (existing != null)
            {
                throw new InvalidOperationException("Character name must be unique");
            }
            ;

            return(AddCore(theCharacter));
        }
示例#2
0
        public Character Add(Character character)
        {
            var item = character;

            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            var validationResults = new ObjectValidator().TryValidateFullobject(item);

            if (validationResults.Count() > 0)
            {
                var builder = new System.Text.StringBuilder();
                foreach (var result in validationResults)
                {
                    builder.AppendLine(result.ErrorMessage);
                }
                ;
                // Show error message
                throw new Exception(builder.ToString());

                // return null;
            }
            ;


            var existing = GetByName(item.Name);

            if (existing != null)
            {
                throw new InvalidOperationException("Character name must be unique");
            }
            try
            {
                return(AddCharacter(item));
            } catch (Exception e)
            {
                //Throwing a new exception
                throw new InvalidOperationException("Add Failed", e);
            };
        }
示例#3
0
        public void Update(int id, Character theCharacter)
        {
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id), "Id must be greater than 0.");
            }
            ;

            if (theCharacter == null)
            {
                throw new ArgumentNullException(nameof(Character));
            }
            ;

            ObjectValidator.Validate(theCharacter);

            var existing = FindByName(theCharacter.Name);

            if (existing != null)
            {
                throw new InvalidOperationException("Character name must be unique");
            }
            ;
            try
            {
                UpdateCore(id, theCharacter);
            }
            catch (ArgumentException e)
            {
                throw;
            }
            catch (InvalidOperationException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new Exception("Update failed", e);
            }
        }
示例#4
0
        public ICharacterDatabase Add(ICharacterDatabase character)
        {
            if (character == null)
            {
                throw new ArgumentNullException(nameof(character));
            }
            ObjectValidator.ValidateFullObject(character);

            var existing = GetByName(character.GetByName());

            if (existing != null)
            {
                throw new InvalidOperationException("Movie must be unique");
            }
            try
            {
                return(AddCore(character));
            } catch (Exception e)
            {
                throw new InvalidOperationException("Add Failed", e);
            };
        }
示例#5
0
        public string Update(int id, Character character)
        {
            var results = new ObjectValidator().TryValidateFullObject(character);

            if (results.Count() > 0)
            {
                foreach (var result in results)
                {
                    return(result.ErrorMessage);
                }
            }
            var existing = GetByName(character.Name);

            if (existing != null && existing.Id != id)
            {
                return("Character name must be unique");
            }

            UpdateCore(id, character);

            return("");
        }
示例#6
0
        public Character Add(Character character)
        {
            if (character == null)
            {
                return(null);
            }

            var results = ObjectValidator.TryValidateObject(character);

            if (results.Count() > 0)
            {
                return(null);
            }

            var existing = GetByNameCore(character.Name);

            if (existing != null)
            {
                return(null);
            }

            return(AddCore(character));
        }
示例#7
0
        public Character Add(Character character)
        {
            if (character == null)
            {
                throw new ArgumentNullException(nameof(character));
            }

            var results = ObjectValidator.TryValidateObject(character);

            if (results.Count() > 0)
            {
                throw new ValidationException(results.FirstOrDefault().ErrorMessage);
            }

            var existing = GetByNameCore(character.Name);

            if (existing != null)
            {
                throw new InvalidOperationException("Character must be unique");
            }

            return(AddCore(character));
        }