public async Task <IActionResult> Edit(int id, [Bind("Id,Career,CV,Name,Phone,Email")] CareerAppliesViewModel careerapplies) { if (ModelState.IsValid) { var row = _context.CareerApplies.Where(x => x.Id == id).FirstOrDefault(); if (careerapplies.CV != null) { string filename = Guid.NewGuid().ToString().Substring(4) + careerapplies.CV.FileName; UploadFile(careerapplies.CV, filename); row.CV = filename; } else { row.CV = row.CV; } row.Id = careerapplies.Id; row.Career = careerapplies.Career; row.Name = careerapplies.Name; row.Phone = careerapplies.Phone; row.Email = careerapplies.Email; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(careerapplies)); }
// GET: CareerApplies/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var careerapplies = _context.CareerApplies.Include(x => x.Career.Pages).Where(x => x.Id == id).FirstOrDefault(); CareerAppliesViewModel model = new CareerAppliesViewModel { Id = careerapplies.Id, Career = careerapplies.Career, Name = careerapplies.Name, Phone = careerapplies.Phone, Email = careerapplies.Email }; if (careerapplies == null) { return(NotFound()); } var pages = _context.Pages.ToList(); ViewBag.Pages = new SelectList(pages, "Id", "Title"); return(View(model)); }
public async Task <IActionResult> Create([Bind("Id,Career,CV,Name,Phone,Email")] CareerAppliesViewModel careerapplies) { if (ModelState.IsValid) { string filename = ""; if (careerapplies.CV != null) { filename = Guid.NewGuid().ToString().Substring(4) + careerapplies.CV.FileName; UploadFile(careerapplies.CV, filename); } CareerApplies careerApplies = new CareerApplies { Id = careerapplies.Id, Career = careerapplies.Career, CV = filename, Name = careerapplies.Name, Email = careerapplies.Email, Phone = careerapplies.Phone }; _context.CareerApplies.Add(careerApplies); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } var pages = _context.Pages.ToList(); ViewBag.Pages = new SelectList(pages, "Id", "Title"); return(View(careerapplies)); }