// 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"));
        }
Exemple #2
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"));
        }
        // 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"));
        }
        // 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());
            }
            CarsModel.Year = CarsModel.Date.Year;
            _context.CarsModel.Add(CarsModel);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemple #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()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

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

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

            var Img = _context.CarImages.Where(a => a.CarsId == id);

            if (Cars != null && Cars.FolderName != null)
            {
                _context.Cars.Remove(Cars);
                foreach (var imgs in Img)
                {
                    _context.CarImages.Remove(imgs);
                }

                var UploadFolder = "wwwroot\\upload";
                var WebRoot      = _hostEnvironment.ContentRootPath;
                var UploadDir    = System.IO.Path.Combine(WebRoot, UploadFolder);

                Directory.Delete(UploadDir + "/" + Cars.FolderName, recursive: true);
                Directory.Delete(UploadDir + "/" + Cars.ThumbFolderName, recursive: true);
                await _context.SaveChangesAsync();
            }
            if (Cars != null && Cars.FolderName == null)
            {
                _context.Cars.Remove(Cars);
                foreach (var imgs in Img)
                {
                    _context.CarImages.Remove(imgs);
                }
                await _context.SaveChangesAsync();
            }

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

            PageContents = await _context.PageInfo.FindAsync(id);

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

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

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

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

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

            Currency = await _context.Currencies.FindAsync(id);

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

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

            Transmission = await _context.Transmissions.FindAsync(id);

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

            return(RedirectToPage("./Index"));
        }
Exemple #11
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"));
        }
Exemple #12
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)
            {
                ModelState.AddModelError("", "One or More Fields is invalid");
                return(Page());
            }

            var ModelId   = Cars.CarsModelId;
            var ModelName = _context.CarsModel.FindAsync(ModelId).Result;

            if (ModelName == null)
            {
                return(NotFound());
            }

            if (FileUpload != null)
            {
                UploadFolder = "upload";
                WebRoot      = _hostingEnvironment.WebRootPath;
                UploadDir    = System.IO.Path.Combine(WebRoot, UploadFolder);


                if (!Directory.Exists(UploadDir))
                {
                    Directory.CreateDirectory(UploadDir);
                }
                //long size = FileUpload.Sum(f => f.Length);

                //Home file upload


                NewString     = CreateRandomString();
                NewFileString = CreateRandomString();
                FileName      = ContentDispositionHeaderValue.Parse(FileUpload.ContentDisposition).FileName.Trim('"');
                Directory.CreateDirectory(UploadDir + "/" + NewString);
                DynamicImageFolder = System.IO.Path.Combine(UploadDir, NewString);
                //var ImageFolder = UploadDir + "/" + NewString;
                // store final final filename
                string FullPath = Path.Combine(DynamicImageFolder, FileName);     // create dynamic string for unique folder
                FileType        = System.IO.Path.GetExtension(FileName);
                FileNameRenamed = NewFileString + FileType;
                if (FileUpload.Length > 0)
                {
                    using (var stream = new FileStream(FullPath, FileMode.Create))
                    {
                        FileUpload.CopyTo(stream);
                        ResizeToFixedSize(FullPath, FileName);                               //crop the uploaded file and rename it
                        System.IO.FileInfo fi = new System.IO.FileInfo(FullPath + FileName); // access the cropped image directory
                        fi.MoveTo(UploadDir + "/" + NewString + "/" + NewFileString + FileType);
                        //fi.Delete(FullPath+FileName);
                    }
                }
            }

            if (MultipleFileUpload.Count > 0 && MultipleFileUpload != null)
            {
                NewThumbString = CreateRandomString();
                Directory.CreateDirectory(UploadDir + "/" + NewThumbString + "/" + "thumbs");
                // save Car data to DB
                Cars.ModelName       = ModelName.Name; // Map Cars ModelName Object to CarsModel Name Object
                Cars.Year            = ModelName.Year;
                Cars.UploadedDate    = DateTime.Now;
                Cars.DisplayFileName = FileNameRenamed;
                Cars.FolderName      = NewString;
                Cars.ThumbFolderName = NewThumbString;
                Cars.ArrayFileName   = "ArrFileName";

                // _context.Database.ExecuteSqlRawAsync("SET IDENTITY_INSERT [dbo].[CarImages] ON");
                _context.Add(Cars);
                await _context.SaveChangesAsync();

                //retrieve last inserted record;

                int counter = 0;
                foreach (IFormFile ModelFile in MultipleFileUpload)    //Home file upload
                {
                    ArrFileName      = ContentDispositionHeaderValue.Parse(ModelFile.ContentDisposition).FileName.Trim('"');
                    ThumbImageFolder = System.IO.Path.Combine(UploadDir, NewThumbString, "thumbs");
                    ArrFileName      = GetUniqueFileName(ArrFileName);
                    string FullPath = Path.Combine(ThumbImageFolder, ArrFileName);     // create dynamic string for unique folder
                                                                                       //FileType = System.IO.Path.GetExtension(FileName);
                    if (MultipleFileUpload.Count > 0)
                    {
                        using (var transaction = _context.Database.BeginTransaction())
                        {
                            using (var stream = new FileStream(FullPath, FileMode.Create))
                            {
                                ModelFile.CopyTo(stream);


                                CarImages.ImagesName  = ArrFileName;
                                CarImages.FolderName  = NewThumbString;
                                CarImages.CarsId      = GetLastCar().Id;
                                CarImages.CreatedDate = DateTime.Now;
                                CarImages.Cid         = AutoId();
                                _context.Add(CarImages);
                                await _context.SaveChangesAsync();

                                transaction.CommitAsync();
                            }
                        }
                    }
                    counter++;
                }

                // _context.Remove(GetLastCar());
                // await _context.SaveChangesAsync();
                Message = "Successful;";
                return(RedirectToPage("./Index"));
            }
            return(this.Content("Failed"));
        }