Esempio n. 1
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            var owner = await _context.Stations.Where(Station => Station.Owner.Id == user.Id).FirstOrDefaultAsync(m => m.Id == Station.Id);

            if (!ModelState.IsValid || user != owner.Owner)
            {
                return(Page());
            }

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

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

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Station.Api   = Guid.NewGuid();
            Station.Owner = await _userManager.GetUserAsync(User);

            _context.Stations.Add(Station);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./StationsIndex"));
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostAsync(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Station = await _context.Stations.FindAsync(id);

            if (Station != null)
            {
                List <Measurement> mesurements = _context.Measurements.Where(x => x.Station == Station).ToList();

                foreach (Measurement mesurement in mesurements)
                {
                    _context.Measurements.Remove(mesurement);
                }

                _context.Stations.Remove(Station);
                await _context.SaveChangesAsync();
            }

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