public async Task <IActionResult> NewCategory() { FileCategories category = new FileCategories { CategoryLabel = Request.Form["categoryLabel"] }; await _context.FileCategories.AddAsync(category); try { await _context.SaveChangesAsync(); if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", category.CategoryLabel))) { Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", category.CategoryLabel)); } } catch (Exception) { return(View("../Shared/Error")); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Delete() { foreach (var key in Request.Form.Keys) { int Id = 0; Int32.TryParse(key, out Id); if (Id == 0) { break; } var file = await _context.FindAsync <Files>(Id); if (file == null) { return(NotFound()); } var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Files", file.FileName); FileInfo info = new FileInfo(path); try { _context.Files.Remove(file); info.Delete(); await _context.SaveChangesAsync(); } catch (Exception) { return(View("../Shared/Error")); } } return(RedirectToAction("Index", "Image")); }
public async Task <ActionResult> Create([Bind(Include = "Id,Name,Issuer,LinkUrl")] Certification certification) { if (ModelState.IsValid) { db.Resumes.FirstOrDefault().Certifications.Add(certification); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(certification)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Name,Description")] Skill skill) { if (ModelState.IsValid) { db.Resumes.FirstOrDefault().Skills.Add(skill); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(skill)); }
public ActionResult NovoAluno([Bind(Include = "ID,Nome,NomeGenitora,DataNascimento,Email,Endereco,Bairro, CEP, UF, Cidade,Telefone,CPF,RG,Observacao,Senha,DataCadastro")] Aluno aluno) { if (ModelState.IsValid) { aluno.CPF = aluno.CPF.Replace("-", "").Replace(".", ""); if (db.Alunos.Where(a => a.CPF.Equals(aluno.CPF)).Count() > 0) { ViewBag.Mensagem = "CPF já cadastrado."; return(View(aluno)); } aluno.DataCadastro = DateTime.Now; aluno.Senha = CryptSharp.MD5Crypter.MD5.Crypt(aluno.Senha); aluno.CEP = aluno.CEP.Replace("-", "").Replace(".", ""); aluno.Telefone = aluno.Telefone.Replace("-", "").Replace(")", "").Replace("(", ""); db.Alunos.Add(aluno); db.SaveChangesAsync(); Session["Aluno"] = aluno; return(RedirectToAction("Index", "Inscricao")); } return(View(aluno)); }
public async Task <IActionResult> New(Users user) { SecurePassword psw = new SecurePassword(); string PasswordSalt = psw.RandomSalt; string UserPassword = psw.GenerateSaltedHash(user.Password); await _context.Users.AddAsync(new Users { UserName = user.UserName, Email = user.Email, Password = UserPassword, PasswordSalt = PasswordSalt }); await _context.SaveChangesAsync(); HttpContext.Session.Set("Authenticated", new byte[1] { 1 }); return(RedirectToAction("Index", "Home")); }
/* * [HttpGet] * public async Task<IActionResult> LoadAllFiles() * { * if (!HttpContext.Session.Keys.Contains<string>("Authenticated")) * { * return View("Unauthorized"); * } * * AllFilesViewModel model = new AllFilesViewModel * { * Images = await _context.Images.ToListAsync<Images>(), * Files = await _context.Files.ToListAsync<Files>(), * Categories = await _context.FileCategories.ToListAsync<FileCategories>(), * FileFolders = await _context.Folders.ToListAsync<Folders>() * }; * * model.Categories = model.Categories.OrderBy<FileCategories, int>(i => i.CategoryId); * model.Images = model.Images.OrderByDescending<Images, DateTime>(t => t.UploadedDate); * model.Files = model.Files.OrderByDescending<Files, DateTime>(t => t.UploadedDate); * * return View("AllFiles", model); * } */ public async Task <IActionResult> Delete(int?Id) { if (!HttpContext.Session.Keys.Contains <string>("Authenticated")) { return(View("Unauthorized")); } if (Id == null) { return(NotFound()); } var img = await _context.FindAsync <Images>(Id); if (img == null) { return(NotFound()); } FileCategories category = await _context.FileCategories.FirstAsync(c => c.CategoryId == img.CategoryId); var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", category.CategoryLabel, img.ImgFileName); var fileInfo = new FileInfo(path); try { _context.Images.Remove(img); if (fileInfo.Exists) { fileInfo.Delete(); } await _context.SaveChangesAsync(); } catch (Exception) { return(View("../Shared/Error")); } return(RedirectToAction("Index")); }