public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }


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

            Property.OwnerID = UserManager.GetUserId(User);
            Ads = await _context.AdsBasicInfo.FindAsync(Property.AdID);

            var isAuthorized = await AuthorizationService.AuthorizeAsync(
                User, Property,
                BaseModelOperations.Create);

            if (!isAuthorized.Succeeded)
            {
                return(Forbid());
            }

            if (Property != null)
            {
                _context.AdsBasicInfo.Remove(Ads);
                _context.Property.Remove(Property);

                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        // 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(AutoMoto).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AutoMotoExists(AutoMoto.AdID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.AdsBasicInfo.Add(Ads);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            return(RedirectToPage("./Index"));
        }
Example #5
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            AutoMoto.AdsBasicInfo.ListingCreated = DateTime.Now;
            AutoMoto.OwnerID = UserManager.GetUserId(User);
            AutoMoto.AdsBasicInfo.OwnerID = AutoMoto.OwnerID;
            AutoMoto.ManufacturerID       = ManufacturerId;
            AutoMoto.ModelID    = ModelId;
            AutoMoto.CategoryId = 9;
            AutoMoto.AdsBasicInfo.CategoryId = AutoMoto.CategoryId;
            _context.AutoMoto.Add(AutoMoto);
            await _context.SaveChangesAsync();

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