示例#1
0
        public async Task <IActionResult> UploadVerfication(IFormFile licenseimg, IFormFile idimg, string useremail)
        {
            User user = await _userManager.FindByEmailAsync(useremail);

            string licenseFileName  = user.UserName + "license";
            string addFileName      = user.UserName + "additional";
            string location         = "/User Document Images";
            string licenseDbName    = null;
            string additionalDbName = null;

            if (user == null)
            {
                TempData["ErrorMessage"] = "User not found";
                return(RedirectToAction("Join", "Home"));
            }

            licenseDbName    = _fileUploader.UploadFileAsync(licenseimg, licenseFileName, location).Result;
            additionalDbName = _fileUploader.UploadFileAsync(licenseimg, addFileName, location).Result;

            //string root = _hostingEnv.WebRootPath;

            //string licenseExt = Path.GetExtension(licenseimg.FileName);
            //string additionalExt = Path.GetExtension(idimg.FileName);

            //string licenseFileName = user.UserName + "license";
            //string additonalFileName = user.UserName + "additional";

            //string licenseDbName = licenseFileName = licenseFileName + DateTime.Now.ToString("yymmssfff") + licenseExt;
            //string additionalDbName = additonalFileName = additonalFileName + DateTime.Now.ToString("yymmssfff") + additionalExt;

            //string licensePath = Path.Combine(root + "/User Document Images", licenseDbName);
            //string additionalPath = Path.Combine(root + "/User Document Images", additionalDbName);

            //using (var filestream = new FileStream(licensePath, FileMode.Create))
            //{
            //    await licenseimg.CopyToAsync(filestream);
            //}

            //using (var filestream = new FileStream(additionalPath, FileMode.Create))
            //{
            //    await idimg.CopyToAsync(filestream);
            //}

            user.License = licenseDbName;
            user.AdditonalIdentification = additionalDbName;
            await _userManager.UpdateAsync(user);

            return(RedirectToAction("SignIn", "Home"));
        }
示例#2
0
        public async Task <IActionResult> Upload(
            IFormFile file,
            string[]?initialTags)
        {
            _logger.LogInformation("Handling file upload");

            var user = await _userManager.FindByIdAsync(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var upload = await _uploadService.UploadFileAsync(file);

            // TODO: Generate Metadata
            // TODO: Tokenize supplied tags and apply
            var newPost = new Post
            {
                Uploader = user,
                Hash     = upload.Hash,
                Metadata = new PostMetadata
                {
                    MimeType = upload.MediaType
                }
            };

            _ = _dbContext.Posts.Add(newPost);
            _ = await _dbContext.SaveChangesAsync();

            // TODO: Less magic thx
            return(Created("http://localhost:5000/Post/" + newPost.Id, true));
        }
示例#3
0
        public JsonResult AddVehicle(string manufacturer, string model, int year, string color, string category, string fuelType, string plate, string rate, IFormFile imageFile)
        {
            string location = "/Vehicle Images";
            string dbName   = null;

            dbName = _fileUploader.UploadFileAsync(imageFile, model, location).Result;

            if (dbName != null)
            {
                Manufacturer man = _manufacturerService.GetFromName(manufacturer);

                if (man == null)
                {
                    _manufacturerService.AddManufacturer(new Manufacturer
                    {
                        ManufacturerName = manufacturer
                    });

                    man = _manufacturerService.GetFromName(manufacturer);
                }

                Vehicle vehicle = new Vehicle
                {
                    Manufacturer = man,
                    Model        = model,
                    Year         = year,
                    Color        = color,
                    Category     = category,
                    FuelType     = fuelType,
                    PlateNumber  = plate,
                    Rate         = Double.Parse(rate),
                    ImageUrl     = dbName
                };

                _vehicleService.AddVehicle(vehicle);

                return(Json("Success"));
            }

            return(Json("Failure"));
        }