public async Task <IActionResult> OnPostAsync()
        {
            Miejsca.Data  = DateTime.Today.ToLongDateString();
            Miejsca.Autor = User.Identity.Name;

            if (!(Zdjecie == null))
            {
                string url = Path.Combine(Environment.CurrentDirectory, "wwwroot/images", Zdjecie.FileName);
                using (var sciezka = new FileStream(url, FileMode.Create))
                {
                    await Zdjecie.CopyToAsync(sciezka);
                }

                Miejsca.Zdjecie = Zdjecie.FileName;
            }

            if (!ModelState.IsValid && Zdjecie == null)
            {
                return(Page());
            }


            _context.Miejsca.Add(Miejsca);
            await _context.SaveChangesAsync();

            ZmiennaGlob.Kategoria = null;
            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostKomentuj()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            KomentarzeZm.IdMiejsca = ZmiennaGlob.Id.ToString();
            KomentarzeZm.Data      = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
            KomentarzeZm.Autor     = User.Identity.Name;


            _context.Komentarze.Add(KomentarzeZm);
            await _context.SaveChangesAsync();

            return(await OnGetAsync(ZmiennaGlob.Id));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Miejsca = await _context.Miejsca.FindAsync(id);

            if (Miejsca != null)
            {
                _context.Miejsca.Remove(Miejsca);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!Miejsca.Data.Contains("Zedytowano"))
            {
                Miejsca.Data = Miejsca.Data + " (Zedytowano)";
            }

            if (!(Zdjecie == null))
            {
                string url = Path.Combine(Environment.CurrentDirectory, "wwwroot/images", Zdjecie.FileName);
                using (var sciezka = new FileStream(url, FileMode.Create))
                {
                    await Zdjecie.CopyToAsync(sciezka);
                }

                Miejsca.Zdjecie = Zdjecie.FileName;
            }

            //if (!ModelState.IsValid)
            //{
            //    return Page();
            //}

            _context.Attach(Miejsca).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MiejscaExists(Miejsca.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }