public Superhero CreateSuperhero(string superheroName, string secretIdentity, string cityName, IEnumerable<string> powerNames)
        {
            if (string.IsNullOrEmpty(superheroName) ||
                superheroName.Length < MinSuperheroNameLength ||
            superheroName.Length > MaxSuperherNameLength)
            {
                throw new ArgumentException("Invalid supehero name");
            }

            var superhero = new Superhero
            {
                SuperheroName = superheroName,
                SecretIdentity = secretIdentity,
                City = this.LoadOrCreateCity(cityName),
                Powers = powerNames?.Select(this.LoadOrCreatePower)
                    .ToList()
            };

            using (this.unitOfWork)
            {
                this.superheroes.Add(superhero);
                this.unitOfWork.Commit();
            }

            return superhero;
        }
Exemplo n.º 2
0
 public void Delete(Superhero Superhero)
 {
     try
     {
         db.Superheroes.Remove(Superhero);
     }
     catch
     {
     }
 }
        public void AddPowerToSuperhero(Superhero superhero, string powerName)
        {
            var dbSuperhero = this.superheroes.GetById(superhero.Id);
            if (dbSuperhero == null)
            {
                throw new ArgumentNullException(nameof(superhero), "Invalid superhero");
            }

            using (unitOfWork)
            {
                dbSuperhero.Powers.Add(this.LoadOrCreatePower(powerName));
                unitOfWork.Commit();
            }
        }
Exemplo n.º 4
0
 public void Add(Superhero Superhero)
 {
     db.Superheroes.Add(Superhero);
 }