public async Task <ActionResult> ViewProfile(int id) { using (DataquadEntities db = new DataquadEntities()) { var userPersonalDetails = db.userPersonalDetails.Where(x => x.userId == id).FirstOrDefault(); ViewBag.userImages = db.userProfileImages.Where(x => x.UserId == id).FirstOrDefault(); ViewBag.files = await GetAllFiles.GetAllFilesByUserId(id); ViewBag.userId = id; return(View(userPersonalDetails)); } }
//To present a view to upload files public async Task <ActionResult> UploadFiles(int?id) { userFilesCollection uploadFileCollection = new userFilesCollection(); uploadFileCollection.UserId = id; using (DataquadEntities db = new DataquadEntities()) { var watch = new Stopwatch(); var files = await GetAllFiles.GetAllFilesByUserId(id); ViewBag.files = files; ViewBag.userImages = ImageFiles(files); } return(View(uploadFileCollection)); }
//Upload files public async Task <ActionResult> UploadFiles(userFilesCollection uploadedFiles, int?userId) { string fileNameString, fileExtensionString; userFilesCollection uploadFileCollection = new userFilesCollection(); if (uploadedFiles.Files[0] != null) { foreach (var file in uploadedFiles.Files) { //Images image = new Images(); fileNameString = (file.FileName.Split('.'))[0]; fileExtensionString = (file.FileName.Split('.'))[1]; uploadFileCollection.FileName = fileNameString; uploadFileCollection.FileExtension = fileExtensionString; uploadFileCollection.FileSize = file.ContentLength; uploadFileCollection.FileContentType = file.ContentType; byte[] data = new byte[file.ContentLength]; file.InputStream.Read(data, 0, file.ContentLength); uploadFileCollection.FileData = data; uploadFileCollection.UserId = userId; DataquadEntities db = new DataquadEntities(); db.userFilesCollections.Add(uploadFileCollection); db.SaveChanges(); } return(RedirectToAction("ViewProfile", "Account", new { id = userId })); } else { ModelState.AddModelError("FileName", "Please select atleast one file to upload"); userFilesCollection uploadFile = new userFilesCollection(); uploadFileCollection.UserId = uploadedFiles.UserId; using (DataquadEntities db = new DataquadEntities()) { var files = await GetAllFiles.GetAllFilesByUserId(uploadedFiles.UserId); ViewBag.files = files; ViewBag.userImages = ImageFiles(files); } return(View("UploadFiles", uploadFileCollection)); } }