Exemple #1
0
        public SuperheroDto CreateOrUpdate(SuperheroDto superhero)
        {
            SuperheroDto result;
            ListItem     superheroEntity;
            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();

            if (!superhero.SuperheroId.HasValue)
            {
                superheroEntity = website.Lists.GetByTitle("Superheroes").AddItem(itemCreateInfo);
            }
            else
            {
                superheroEntity = website.Lists.GetByTitle("Superheroes").GetItemById(Convert.ToInt32(superhero.SuperheroId));
            }

            superheroEntity["Title"]       = superhero.superheroName;
            superheroEntity["description"] = superhero.description;
            superheroEntity["actor"]       = superhero.actor;
            superheroEntity["superpower"]  = superhero.superpower;
            superheroEntity["side"]        = superhero.side;

            result = mapper.Map <SuperheroDto>(superheroEntity);


            return(result);
        }
Exemple #2
0
        public IHttpActionResult GetSuperhero(int id)
        {
            SuperheroDto result = superheroRepository.GetById(id);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
Exemple #3
0
        public IHttpActionResult PostSuperhero(SuperheroDto superhero)
        {
            SuperheroDto result;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            result = superheroRepository.CreateOrUpdate(superhero);

            return(Ok(result));
        }
        public SuperheroDto GetById(int id)
        {
            SuperheroDto result = null;

            Superhero superheroEntity = dbContext.Superheroes.Find(id);

            if (superheroEntity != null)
            {
                result = mapper.Map <SuperheroDto>(superheroEntity);
            }

            return(result);
        }
Exemple #5
0
        public SuperheroDto GetById(int id)
        {
            SuperheroDto result = null;

            ListItem superheroEntity = website.Lists.GetByTitle("Superheroes").GetItemById(id);

            clientContext.Load(superheroEntity);
            clientContext.ExecuteQuery();

            if (superheroEntity != null)
            {
                result = mapper.Map <SuperheroDto>(superheroEntity);
            }

            return(result);
        }
Exemple #6
0
        public string ExportSuperheroDetails(object superheroId)
        {
            var hero = this.db.Superheroes.GetById(superheroId);
            var dto  = new SuperheroDto()
            {
                Name           = hero.Name,
                City           = hero.City.Name,
                Alignment      = hero.Alignment.ToString(),
                Id             = hero.Id,
                SecretIdentity = hero.SecretIdentity,
                Powers         = hero.Powers.Select(p => p.Name).ToArray()
            };
            var container = new SuperheroesCollection {
                Superheroes = new[] { dto }
            };

            var result = Serialize(container, $"HeroWithId{(int)superheroId}-Export.xml");

            return(result);
        }
        public SuperheroDto CreateOrUpdate(SuperheroDto superhero)
        {
            SuperheroDto result;
            Superhero    superheroEntity;

            if (!superhero.SuperheroId.HasValue)
            {
                superheroEntity = new Superhero();
                dbContext.Superheroes.Add(superheroEntity);
            }
            else
            {
                superheroEntity = dbContext.Superheroes.Find(superhero.SuperheroId);
            }

            mapper.Map(superhero, superheroEntity);

            dbContext.SaveChanges();

            result = mapper.Map <SuperheroDto>(superheroEntity);

            return(result);
        }