Beispiel #1
0
        public async Task <IActionResult> Create(IntroPersonalViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var model   = new IntroPersonal(viewModel);
                var webRoot = _env.WebRootPath;
                if (viewModel.Picture != null)
                {
                    Tuple <bool, string> result = await _spiikService.SaveFile(viewModel.Picture, "images/IntroPersonal", viewModel.Name);

                    if (result.Item1)                                 // Success saving
                    {
                        if (!string.IsNullOrWhiteSpace(result.Item2)) // Spara endast om en bild har blivit uppladdad.
                        {
                            model.PictureSrc = result.Item2;
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("Picture", result.Item2);
                        return(View());
                    }
                }
                await _db.AddAsync(model);

                await _db.SaveChangesAsync();

                TempData["Message"] = "Personal skapad!";
                return(RedirectToAction("Index"));
            }
            return(View(viewModel));
        }
Beispiel #2
0
 public IntroPersonalViewModel(IntroPersonal model)
 {
     Id         = model.Id;
     Name       = model.Name;
     NickName   = model.NickName;
     Age        = model.Age;
     Program    = model.Program;
     Quote      = model.Quote;
     Bribe      = model.Bribe;
     GoodWord   = model.GoodWord;
     PictureSrc = model.PictureSrc;
     IntroType  = model.IntroType;
 }