public int CreateCareer(CareerVM model) { try { if (string.IsNullOrEmpty(model.Firstname) || model.Firstname.Count() < 3) { throw new Exception("Can not be empty field!"); } if (string.IsNullOrEmpty(model.Description) || model.Description.Count() < 3) { throw new Exception("Can not be empty field!"); } Career career = new Career { Id = model.Id, Firstname = model.Firstname, Lastname = model.Lastname, Phone = model.Phone, Description = model.Description, Resume = model.Resume.FileName }; //career.Resume = model.Resume.FileName; //var mappedCareer = _mapper.Map<Career>(model); return(_careerRepo.Insert(career)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public IActionResult Create() { _toastNotification.AddInfoToastMessage("For a job application, all fields must be filled out."); CareerVM model = new CareerVM(); return(View(model)); }
public IActionResult Create(CareerVM model) { try { if (ModelState.IsValid) { var allResume = _career.GetAllResumes().ToList(); if (model.Resume != null) { ViewBag.ErrorFileLength = "File is to large"; foreach (var resume in allResume) { if (model.Resume.FileName == resume) { ViewBag.errorResumeMsg = "Can not upload same resume!"; return(View(model)); } } string uploadFolder = Path.Combine(_env.WebRootPath, "data/resumes"); string uniqueFilename = model.Resume.FileName; string filePath = Path.Combine(uploadFolder, uniqueFilename); string extension = Path.GetExtension(filePath); if (!ServiceHelper.IsItDocument(model.Resume)) { ViewBag.errorUploadMsg = "Only Microsoft word and pdf files allowed."; } else { model.Resume.CopyTo(new FileStream(filePath, FileMode.Create)); _career.CreateCareer(model); _toastNotification.AddSuccessToastMessage("the application has been successfully submitted. " + "Thank you and after reviewing your application, we will send you an answer."); return(RedirectToAction("index", "home")); } } } } catch (Exception ex) { Log.Error($"{ex.Message}"); } return(View(model)); }
public CareerVM GetById(int id) { try { var career = _careerRepo.GetById(id); CareerVM model = _mapper.Map <CareerVM>(career); if (model != null) { return(model); } else { throw new Exception($"Career with id: {id} does not exist"); } } catch (Exception ex) { throw new Exception(ex.Message); } }