public async Task <ActionResult> UploadAsync(string Id)
        {
            try
            {
                var request = await HttpContext.Request.ReadFormAsync();

                if (request.Files == null)
                {
                    return(BadRequest("Could not upload files"));
                }
                var files = request.Files;
                if (files.Count == 0)
                {
                    return(BadRequest("Could not upload empty files"));
                }

                await _azureBlobService.UploadAsync(files, Id);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewData["message"] = ex.Message;
                ViewData["trace"]   = ex.StackTrace;
                return(View("Error"));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UploadBlob([FromForm] FileUpload objFile)
        {
            //List<User> userList = JsonConvert.DeserializeObject<List<User>>(objFile.users);
            if (objFile.files.Count > 0)
            {
                var files = objFile.files;
                await _azureBlobService.UploadAsync(files);

                return(Ok("Image successfully uploaded"));
            }
            return(null);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UploadImages()
        {
            int userId  = int.Parse(User.Claims.FirstOrDefault(x => x.Type.Equals("UserId")).Value);
            var request = await HttpContext.Request.ReadFormAsync();

            if (!await _listingService.UserOwnsListing(userId, int.Parse(request["listingId"])))
            {
                return(BadRequest(new { error = "You do not have sufficient permissions or the listing does not exist" }));
            }
            List <IFormFile> files = request.Files.Where(x => x.ContentType.StartsWith("image")).ToList();
            await _azureBlobService.UploadAsync(files, $"l/{request["listingId"]}/");

            return(Ok());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UploadImageAsync()
        {
            int userId  = int.Parse(User.Claims.FirstOrDefault(x => x.Type.Equals("UserId")).Value);
            var request = await HttpContext.Request.ReadFormAsync();

            List <IFormFile> files = request.Files.Where(x => x.ContentType.StartsWith("image")).ToList();

            if (files == null || files.Count == 0)
            {
                return(BadRequest());
            }
            await _azureBlobService.UploadAsync(files, $"u/{userId}/", "profile");

            return(Ok());
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> UploadAsync()
        {
            var request = await HttpContext.Request.ReadFormAsync();

            if (request.Files == null)
            {
                return(BadRequest( ));
            }
            var files = request.Files;

            if (files.Count == 0)
            {
                return(BadRequest(new ApiResponse(400, "Could not upload empty files")));
            }

            await _azureBlobService.UploadAsync(files);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Apply(JobApplication model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var request = await HttpContext.Request.ReadFormAsync();

            var    files = request.Files;
            string url   = "";

            if (files != null && files.Count != 0)
            {
                string name = string.Format("{0:10}_{1}{2}", DateTime.Now.Ticks, Guid.NewGuid(), Path.GetExtension(files[0].FileName));

                var uri = _azureBlobService.UploadAsync(files, name);
                url = uri.Result.AbsoluteUri;
            }
            var user = FindUser(User);

            JobApplication ja = new JobApplication
            {
                JobOfferId  = model.JobOfferId,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                PhoneNumber = model.PhoneNumber,
                CvUrl       = url,
                UserId      = user.Id
            };
            var offer = await _context.JobOffers.Include(x => x.User).FirstOrDefaultAsync(x => x.Id == ja.JobOfferId);


            await SendMessage(user, offer.User, "Somebody appiled to your job offer!");

            await _context.JobApplications.AddAsync(ja);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = model.JobOfferId }));
        }
        public async Task <ActionResult> Edit(JobApplication model)
        {
            if (!ModelState.IsValid)
            {
                var cos = await _context.JobApplications.Include(x => x.JobOffer).FirstOrDefaultAsync(x => x.Id == model.Id);

                return(View(cos));
            }
            var offer = await _context.JobApplications.Include(x => x.JobOffer).FirstOrDefaultAsync(x => x.Id == model.Id);

            var request = await HttpContext.Request.ReadFormAsync();

            var files = request.Files;

            if (files != null && files.Count != 0)
            {
                string name = string.Format("{0:10}_{1}{2}", DateTime.Now.Ticks, Guid.NewGuid(), Path.GetExtension(files[0].FileName));

                var uri = _azureBlobService.UploadAsync(files, name);
                if (offer.CvUrl != "")
                {
                    await _azureBlobService.DeleteAsync(offer.CvUrl);
                }
                offer.CvUrl = uri.Result.AbsoluteUri;
            }



            offer.FirstName   = model.FirstName;
            offer.LastName    = model.LastName;
            offer.PhoneNumber = model.PhoneNumber;



            _context.Update(offer);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = model.Id }));
        }