コード例 #1
0
        public async Task <IActionResult> Create(CandidateVM candidate)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var imageTitle = _candidateRepository.AddImage(candidate.Image, _webHostEnvironment);
                    var fileName   = await _candidateRepository.AddResumeAsync(candidate.Resume, _webHostEnvironment);

                    var newCandidate = new Candidate()
                    {
                        FullName   = candidate.FullName,
                        JobTitle   = candidate.JobTitle,
                        Age        = candidate.Age,
                        City       = candidate.City,
                        Area       = candidate.Area,
                        Address    = candidate.Address,
                        ImageTitle = imageTitle,
                        FileName   = fileName
                    };

                    await _candidateRepository.AddAsync(newCandidate);

                    await _candidateRepository.SaveAllAsync();

                    return(View("Details", newCandidate));
                }
                catch (Exception)
                {
                    return(View());
                }
            }

            return(View());
        }