Example #1
0
        public IActionResult Create()
        {
            // var bikes = _context.Bikes.Include(x => x.Make).Include(x => x.Model);
            if (!ModelState.IsValid)
            {
                BikeVM.Makes  = _context.Make.ToList();
                BikeVM.Models = _context.Models.ToList();

                return(View(BikeVM));
            }
            UploadImageUpload();
            _context.Models.Add(BikeVM.Model);
            _context.SaveChanges();

            var    bikeId     = BikeVM.Bike.Id;
            string wwroot     = _hostingEnvironment.WebRootPath;
            var    files      = HttpContext.Request.Form.Files();
            var    savedBikes = _context.Bikes.Find(bikeId);

            if (files.Count > 0)
            {
                var imagePath         = @"images\bikes";
                var extension         = Path.GetExtension(files[0].FileName);
                var relativeImagePath = imagePath + bikeId + extension;
                var absImg            = imagePath.Combine(wwroot, relativeImagePath);
            }
            using (var fileStream = new FilStream(absImg, FileMode.Create))
            {
                files[0].CopyTo(fileStream);
            }
            savedBikes.ImagePath = relativeImagePath;
            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
 public IActionResult CreatePost()
 {
     if (!ModelState.IsValid)
     {
         return(View(ModelVm));
     }
     _context.Models.Add(ModelVm.Model);
     _context.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }
Example #3
0
 public IActionResult Create(Make make)
 {
     if (ModelState.IsValid)
     {
         _db.Makes.Add(make);
         _db.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(make));
 }
 public IActionResult CreatePost()
 {
     if (!ModelState.IsValid)
     {
         return(View(ModelVM));
     }
     _db.models.Add(ModelVM.Model);
     _db.SaveChanges();
     HttpContext.Session.SetString("Message", "success");
     return(RedirectToAction(nameof(Index)));
 }
Example #5
0
 public IActionResult EditPost()
 {
     if (!ModelState.IsValid)
     {
         BikeVM.Makes  = _db.Makes.ToList();
         BikeVM.Models = _db.Models.ToList();
         return(View(BikeVM));
     }
     _db.Bikes.Update(BikeVM.Bike);
     UploadImageIfAvailable();
     _db.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }
 public ActionResult CreatePost()
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(View(ModelVM));
         }
         _db.Models.Add(ModelVM.Model);
         _db.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Example #7
0
 public IActionResult CreatePost()
 {
     if (!ModelState.IsValid)
     {
         BikeVM.Makes  = _db.Makes.ToList();
         BikeVM.Models = _db.Models.ToList();
         return(View(BikeVM));
     }
     if (BikeVM.Bike.ModelID == 0)
     {
         ViewBag.Message = "Please select a Model from the list";
         return(View(BikeVM));
     }
     _db.Bikes.Add(BikeVM.Bike);
     UploadImage();
     _db.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }
Example #8
0
        public IActionResult CreatePost()
        {
            if (!ModelState.IsValid)
            {
                BikeVM.Makes  = _db.Makes.ToList();
                BikeVM.Models = _db.Models.ToList();
                return(View(BikeVM));
            }
            _db.Bikes.Add(BikeVM.Bike);
            //_db.SaveChanges();

            //save bike Logic
            //get bike id we have saved in database
            var BikeID = BikeVM.Bike.Id;

            //get wwwroot path to save file in folder
            string wwrootpath = _hostingEnvironment.WebRootPath;

            //get uploaded files
            var files = HttpContext.Request.Form.Files;

            //get reference of DBset for bike just have saved in database
            var SavedBike = _db.Bikes.Find(BikeID);

            //upload the file on server and save image  pathe of user
            if (files.Count != 0)
            {
                var ImagePath         = @"Image\bike\";
                var Extension         = Path.GetExtension(files[0].FileName);
                var relativeImagePath = ImagePath + BikeID + Extension;
                var AbsImagePath      = Path.Combine(wwrootpath, relativeImagePath);

                //upload file on server
                using (var fileStream = new FileStream(AbsImagePath, FileMode.Create))
                {
                    files[0].CopyTo(fileStream);
                }
                //set Image path to database
                SavedBike.ImagePath = relativeImagePath;
                _db.SaveChanges();
            }

            return(RedirectToAction(nameof(Index)));
        }
 public ActionResult CreatePost()
 {
     try
     {
         if (!ModelState.IsValid)
         {
             BikeVM.Makes  = _db.Makes.ToList();
             BikeVM.Models = _db.Models.ToList();
             return(View(BikeVM));
         }
         _db.Bikes.Add(BikeVM.Bike);
         _db.SaveChanges();
         //Get Bike ID
         var BikeID = BikeVM.Bike.Id;
         //Get WWWRootPath To Save File On Server
         string wwwRootPath = _hostEnvironment.WebRootPath;
         //Get The UploadFiles
         var files = HttpContext.Request.Form.Files;
         //Get The Reference of DBSet for the Bike We Just Have Saved In DB
         var SavedBike = _db.Bikes.Find(BikeID);
         //Upload File On Server And Save Image Path
         if (files.Count != 0)
         {
             var ImagePath         = @"images\bike\";
             var Extensions        = Path.GetExtension(files[0].FileName);
             var RelativeImagePath = ImagePath + BikeID + Extensions;
             var AbsImagePath      = Path.Combine(wwwRootPath, RelativeImagePath);
             //Upload File On The Server
             using (var fileStrem = new FileStream(AbsImagePath, FileMode.Create))
             {
                 files[0].CopyTo(fileStrem);
             }
             //Set The ImagePathTO Data base
             SavedBike.ImagePath = RelativeImagePath;
             _db.SaveChanges();
         }
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Example #10
0
 public IActionResult CreatePost()
 {
     if (!ModelState.IsValid)
     {
         return(View(ModelVM));
     }
     _vroomDb.Models.Add(ModelVM.Model);
     _vroomDb.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }
        public IActionResult CreatePost()
        {
            if (!ModelState.IsValid)
            {
                BikeVM.Makes  = _db.makes.ToList();
                BikeVM.Models = _db.models.ToList();
                return(View(BikeVM));
            }
            _db.Bikes.Add(BikeVM.Bike);
            _db.SaveChanges();

            var BikeId = BikeVM.Bike.Id;

            string wwrootPath = _hostingenvironment.WebRootPath;

            var files = HttpContext.Request.Form.Files;

            var savedBike = _db.Bikes.Find(BikeId);

            if (files.Count != 0)
            {
                var ImagePath         = @"images\bike";
                var Extension         = Path.GetExtension(files[0].FileName);
                var RelativeImagePath = ImagePath + BikeId + Extension;
                var AbsImagePath      = Path.Combine(wwrootPath, RelativeImagePath);

                using (var filestream = new FileStream(AbsImagePath, FileMode.Create))
                {
                    files[0].CopyTo(filestream);
                }

                savedBike.ImagePath = RelativeImagePath;
                _db.SaveChanges();
            }

            HttpContext.Session.SetString("Message", "success");
            return(RedirectToAction(nameof(Index)));
        }
 public int Insert(Loanusers item)
 {
     // throw new NotImplementedException();
     // Loanusers dbsave = new Loanusers();
     //var newloan = new Loanusers()
     //{
     //    FirstName = item.FirstName,
     //    LastName = item.LastName,
     //    Phoneno = item.Phoneno,
     //    address = item.address,
     //    Loanstatus = item.Loanstatus,
     //    ImagePath = item.ImagePath,
     //};
     _db.Loanusers.Add(item);
     _db.SaveChanges();
     return(item.Id);
 }
        public int Insert(LoanuserViewModels item)
        {
            // throw new NotImplementedException();

            var newloan = new Loanusers()
            {
                FirstName  = item.FirstName,
                LastName   = item.LastName,
                Phoneno    = item.Phoneno,
                address    = item.address,
                Loanstatus = item.Loanstatus,
                ImagePath  = item.ImagePath,
            };

            _db.Loanusers.Add(newloan);
            _db.SaveChanges();
            return(newloan.Id);
        }
        public IActionResult Insert(LoanuserViewModels item)
        {
            var newloan = new Loanusers()
            {
                FirstName  = item.lu.FirstName,
                LastName   = item.lu.LastName,
                Phoneno    = item.lu.Phoneno,
                address    = item.lu.address,
                Loanstatus = item.lu.Loanstatus,
                ImagePath  = item.lu.ImagePath,
            };
            int id = _loanServiceemployee.Insert(newloan);
            //var BikeId = BikeVM.Bike.Id;
            var loanid = id;

            string wwrootPath = _hostingenvironment.WebRootPath;

            var files = HttpContext.Request.Form.Files;

            var savedBike = _db.Loanusers.Find(loanid);

            if (files.Count != 0)
            {
                var ImagePath         = @"images";
                var Extension         = Path.GetExtension(files[0].FileName);
                var RelativeImagePath = ImagePath + loanid + Extension;
                var AbsImagePath      = Path.Combine(wwrootPath, RelativeImagePath);

                using (var filestream = new FileStream(AbsImagePath, FileMode.Create))
                {
                    files[0].CopyTo(filestream);
                }

                savedBike.ImagePath = RelativeImagePath;
                _db.SaveChanges();
            }
            return(View(Luvm));
        }