示例#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(Currency).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CurrencyExists(Currency.CurrencyId))
                {
                    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());
            }

            _context.Attach(CarsModel).State = EntityState.Modified;
            CarsModel.Year = CarsModel.Date.Year;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarsModelExists(CarsModel.CarsModelId))
                {
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }

                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#3
0
        public async Task <IActionResult> OnPostAsync()
        {
            //if (!ModelState.IsValid)
            //{
            //    return Page();
            //}

            var data = await _context.Cars.FindAsync(Cars.Id);

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

            try
            {
                data.Price      = Cars.Price;
                data.PriceNaira = Cars.PriceNaira;
                await _context.SaveChangesAsync();
            }

            catch (DbUpdateConcurrencyException)
            {
                if (!CarExists(Cars.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#4
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(Cars).State = EntityState.Modified;
            var ModelId   = Cars.CarsModelId;
            var cid       = Cars.Id;
            var ModelName = _context.CarsModel.FindAsync(ModelId).Result;

            Cars = _context.Cars.FindAsync(cid).Result;

            if (FileUpload == null && MultipleFileUpload.Count == 0)
            {
                Cars.DisplayFileName = Cars.DisplayFileName;
                Cars.FolderName      = Cars.FolderName;
                Cars.ArrayFileName   = Cars.ArrayFileName;
                Cars.ThumbFolderName = Cars.ThumbFolderName;

                //_context.Remove(Cars.ThumbFolderName).State = EntityState.Detached;
                //_context.Remove(Cars.FolderName).State = EntityState.Detached;
                //_context.Remove(Cars.ArrayFileName).State = EntityState.Detached;
                //_context.Remove(Cars.DisplayFileName).State = EntityState.Detached;
            }

            try  // process properties or fields changes to database
            {
                Cars.ModelName = ModelName.Name;
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                ModelState.AddModelError("", "Unable to save changes.Try again, and if the problem persists, see your system administrator.");
            }

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