コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount,Adresa,Grad,Ime,Prezime,Telefon")] AspNetUser aspNetUser)
        {
            if (ModelState.IsValid)
            {
                db.Add(aspNetUser);
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aspNetUser));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("VoziloId,MarkaId,ModelId,TipVozilaId,KorisnikId,Kubikaza,Snaga,Kilometraza,Pogon,Menjac,BrojBrzina,Cena,Slika,SlikaTip,Opis")]
                                                 Vozilo vozilo, IFormFile odabranaSlika)
        {
            if (odabranaSlika == null)
            {
                ModelState.AddModelError("FajlSlike", "Niste");
            }
            if (ModelState.IsValid)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    await odabranaSlika.CopyToAsync(ms);

                    vozilo.Slika = ms.ToArray();
                }
                vozilo.SlikaTip = odabranaSlika.ContentType;
                db.Add(vozilo);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View(vozilo));
        }