Exemplo n.º 1
0
        public IActionResult Edit(IFormFile avatar, CandidateEditViewModel candidateView)
        {
            if (ModelState.IsValid)
            {
                _candidateService.EditCandidate(avatar, candidateView);

                return(RedirectToAction(nameof(Index)));
            }

            return(RedirectToAction(nameof(Edit)));
        }
Exemplo n.º 2
0
        public async Task <CandidateEditViewModel> GetCandidate(int id)
        {
            //return new CandidateEditViewModel
            //{
            //	FirstName = "joel",
            //	Id = 1,
            //	Surname = "Lister",
            //	Excluded = true,
            //	Notes = new List<NoteViewModel>
            //	{
            //		new NoteViewModel{Index = 1,DateEntered = DateTimeOffset.Now.AddDays(-1), NoteText = "Test sample 1"},
            //		new NoteViewModel{Index = 2,DateEntered = DateTimeOffset.Now, NoteText = "Test sample 2"},
            //	}
            //};


            var url      = $"https://www.peg-em.com/v1/candidate/{id}";
            var response = await Client.GetAsync(url);

            if (!response.IsSuccessStatusCode)
            {
                //TODO: log error
            }
            var candidateResponse = await response.Content.ReadAsAsync <CandidateResponse>();

            var candidate = new CandidateEditViewModel
            {
                Id        = candidateResponse.Id,
                FirstName = candidateResponse.Name,
                Surname   = candidateResponse.Surname,
                Excluded  = candidateResponse.Excluded > 0,
                Notes     = new List <NoteViewModel>()
            };

            if (candidateResponse.Notes == null)
            {
                return(candidate);
            }

            var index = 0;

            foreach (var note in candidateResponse.Notes)
            {
                candidate.Notes.Add(new NoteViewModel {
                    Index = index, DateEntered = ToLocalTime(note.DateEntered), NoteText = note.Text
                });
                index++;
            }

            return(candidate);
        }
Exemplo n.º 3
0
        public void EditCandidate(IFormFile avatar, CandidateEditViewModel candidateView)
        {
            string path;

            if (avatar != null)
            {
                /*upload file*/
                var storagePath = Path.Combine(_hostingEnvironment.WebRootPath, "images", avatar.FileName);
                path = "/images/" + avatar.FileName;
                var stream = new FileStream(storagePath, FileMode.Create);
                avatar.CopyToAsync(stream);

                Candidate candidate = new Candidate()
                {
                    Id        = candidateView.Id,
                    Name      = candidateView.Name,
                    Phone     = candidateView.Phone,
                    VacancyID = candidateView.VacancyId,
                    Avatar    = path,
                };

                _context.Candidates.Update(candidate);
                _context.SaveChanges();
            }
            else
            {
                path = GetCandidateByID(candidateView.Id).Avatar;

                Candidate candidate = new Candidate()
                {
                    Id        = candidateView.Id,
                    Name      = candidateView.Name,
                    Phone     = candidateView.Phone,
                    VacancyID = candidateView.VacancyId,
                    Avatar    = path,
                };

                _context.Candidates.Update(candidate);
                _context.SaveChanges();
            }
        }