예제 #1
0
        // To protect from overposting attacks, 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());
            }

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

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

            return(RedirectToPage("./Index"));
        }
예제 #2
0
        // To protect from overposting attacks, 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());
            }
            var user = await _userManager.GetUserAsync(HttpContext.User);

            CustomMapping.Owner = user;
            _context.CustomMapping.Add(CustomMapping);
            await _context.Database.OpenConnectionAsync();

            try
            {
                await _context.Database.ExecuteSqlRawAsync("SET IDENTITY_INSERT dbo.CustomMapping ON");

                await _context.SaveChangesAsync();

                await _context.Database.ExecuteSqlRawAsync("SET IDENTITY_INSERT dbo.CustomMapping OFF");
            }
            finally
            {
                await _context.Database.CloseConnectionAsync();
            }

            return(RedirectToPage("./Index"));
        }
예제 #3
0
        public async Task <IActionResult> OnPostAsync(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            return(RedirectToPage("./Index"));
        }
예제 #4
0
        public async Task <IActionResult> OnPostAsync(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var target = _context.CustomMapping.Find(CustomMapping.Id);

            if (user != target.Owner)
            {
                return(Unauthorized());
            }
            CustomMapping = await _context.CustomMapping.FindAsync(id);

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

            return(RedirectToPage("./Index"));
        }
예제 #5
0
        // To protect from overposting attacks, 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(HttpContext.User);

            var target = _context.Mapping.Find(Mapping.Id);

            _context.Entry(target).State = EntityState.Detached;
            if (user != target.Owner)
            {
                return(Unauthorized());
            }
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Mapping.OwnerId = target.OwnerId;
            _context.Attach(Mapping).State = EntityState.Modified;

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

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