Beispiel #1
0
        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));
        }