Exemplo n.º 1
0
        public IActionResult Create(PollCreateDto model, IFormFile file)
        {
            var poll = new Poll();

            _mapper.Map(model.Poll, poll);
            poll.Created = DateTime.Now;
            var pollitem = new PollItem();

            _mapper.Map(model.Item, pollitem);

            poll.PollItems.Add(pollitem);

            var pollImage = new Image();

            if (file != null)
            {
                pollImage.FileName = Path.GetFileName(file.FileName);
                pollImage.Content  = ImageHelper.ReadImage(file.OpenReadStream());
                pollitem.Images.Add(pollImage);
            }


            _context.Add(poll);
            _context.Add(pollitem);
            if (pollImage.Content != null)
            {
                pollitem.Images.Add(pollImage);
                _context.Add(pollImage);
            }

            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 public void Seed(IFLikeContext context)
 {
     if (context.Countries.Any())
     {
         return;
     }
     Country[] countries =
     {
         new Country()
         {
             CountryCode = "dk", IsAllowed = true, Name = "Denmark"
         },
         new Country()
         {
             CountryCode = "no", IsAllowed = true, Name = "Norway"
         },
         new Country()
         {
             CountryCode = "se", IsAllowed = true, Name = "Sweden"
         },
         new Country()
         {
             CountryCode = "fi", IsAllowed = true, Name = "Finland"
         },
         new Country()
         {
             CountryCode = "es", IsAllowed = true, Name = "Estonia"
         },
         new Country()
         {
             CountryCode = "lv", IsAllowed = true, Name = "Latvia"
         },
         new Country()
         {
             CountryCode = "lt", IsAllowed = true, Name = "Lithuania"
         },
     };
     foreach (var country in countries)
     {
         context.Add(country);
     }
     context.SaveChanges();
 }