public async System.Threading.Tasks.Task UpdateCandidate()
        {
            // Arrange
            var candidateContent = new MyCandidate();

            candidateContent.ResourceRequisition = "edited Manager";
            candidateContent.CandidateEmail      = "*****@*****.**";
            candidateContent.Stages        = 3;
            candidateContent.ResumeText    = "edited resume";
            candidateContent.ResumeUpload  = "";
            candidateContent.PanelDeadline = new DateTime();
            var payload = new StringContent(JsonConvert.SerializeObject(candidateContent),
                                            Encoding.UTF8, "application/json");

            // Act
            var response = await Client.PutAsync("/api/Candidate/9999", payload);

            response.EnsureSuccessStatusCode();

            // Asserts
            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            var o = JsonConvert.DeserializeObject <MyCandidate>(response.Content.ReadAsStringAsync().Result);

            Assert.Equal(o.ResourceRequisition, "edited Manager");
        }
Example #2
0
        public ActionResult CreateCandidate(MyCandidate candidate, HttpPostedFileBase imageFile)
        {
            if (!ModelState.IsValid)
            {
                MessageForClient(ActionStatus.Error, $"Указанные данные не валидны.");
                return(RedirectToAction("Index", "Home"));
            }
            var savingCandidate = _mapper.Map <MyCandidate, CandidateBase>(candidate);
            var identityUser    = _userRepository.FindUser(User.Identity.Name);

            if (identityUser.Status != ActionStatus.Success)
            {
                MessageForClient(ActionStatus.Error, $"Не удалось найти пользователя, которому требуется добавить объявление.");
                return(RedirectToAction("Index", "Home"));
            }
            savingCandidate.Creator    = identityUser.Entity.First() as UserBase;
            savingCandidate.LastEditor = savingCandidate.Creator;
            if (imageFile != null)
            {
                byte[] buf = new byte[imageFile.ContentLength];
                imageFile.InputStream.Read(buf, 0, imageFile.ContentLength);
                savingCandidate.Photo = buf;
            }
            var updatedResult = _announcementRepository.CreateAnnouncement(savingCandidate);

            MessageForClient(updatedResult.Status, updatedResult.Message);
            if (updatedResult.Status != ActionStatus.Success)
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("ShowUser", "User", new { (updatedResult.Entity.First() as CandidateBase).Creator.Login }));
        }
        public IActionResult Create(MyCandidate candidates)
        {
            if (candidates.Id == null)
            {
                Guid   obj = Guid.NewGuid();
                string gid = obj.ToString();
                candidates.Id = gid;
            }
            _context.MyCandidates.Add(candidates);
            _context.SaveChanges();
            var data = _context.MyCandidates.Find(candidates.Id);

            return(CreatedAtRoute("GetCandidateDetails", new { id = candidates.Id }, candidates));
        }
Example #4
0
        public void Seed()
        {
            var candidateContent = new MyCandidate();

            candidateContent.Id = "9999";
            candidateContent.ResourceRequisition = "Seed Manager";
            candidateContent.CandidateEmail      = "*****@*****.**";
            candidateContent.Stages        = 3;
            candidateContent.ResumeText    = "Seed Resume";
            candidateContent.ResumeUpload  = "";
            candidateContent.PanelDeadline = new DateTime();
            _context.MyCandidates.Add(candidateContent);
            _context.SaveChanges();
        }
        public IActionResult Put(string id, MyCandidate candidates)
        {
            var data = _context.MyCandidates.Find(id);

            data.ResourceRequisition = candidates.ResourceRequisition;
            data.CandidateEmail      = candidates.CandidateEmail;
            data.Stages        = candidates.Stages;
            data.ResumeText    = candidates.ResumeText;
            data.ResumeUpload  = candidates.ResumeUpload;
            data.Stages        = candidates.Stages;
            data.PanelDeadline = candidates.PanelDeadline;
            _context.MyCandidates.Update(data);
            _context.SaveChanges();
            data = _context.MyCandidates.Find(id);
            return(CreatedAtRoute("GetCandidateDetails", new { id = id }, candidates));
        }
        public async System.Threading.Tasks.Task AddCandidate()
        {
            var candidateContent = new MyCandidate();

            candidateContent.Id = "f13c1a0a-1f70-4fc0-8aa8-6a4986640280";
            candidateContent.ResourceRequisition = "Manager";
            candidateContent.CandidateEmail      = "*****@*****.**";
            candidateContent.Stages        = 2;
            candidateContent.ResumeText    = "CAsca";
            candidateContent.ResumeUpload  = "";
            candidateContent.PanelDeadline = new DateTime();
            var payload = new StringContent(JsonConvert.SerializeObject(candidateContent),
                                            Encoding.UTF8, "application/json");
            var response = await Client.PostAsync("/api/Candidate/addCandidates", payload);

            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
Example #7
0
        public ActionResult EditCandidate(MyCandidate editingCandidate, HttpPostedFileBase imageFile)
        {
            if (!ModelState.IsValid)
            {
                MessageForClient(ActionStatus.Error, $"Указанные данные не валидны.");
                return(RedirectToAction("Index", "Home"));
            }
            var repositoryResult = _announcementRepository.FindAnnouncement(editingCandidate.Id);

            if (repositoryResult.Status != ActionStatus.Success)
            {
                MessageForClient(repositoryResult.Status, repositoryResult.Message);
                return(RedirectToAction("Index", "Home"));
            }
            if ((repositoryResult.Entity.First() as CandidateBase).Creator.Login != User.Identity.Name && !User.IsInRole("Admin"))
            {
                MessageForClient(ActionStatus.Error, "У вас недостаточно прав для редактирования данного объявления!");
                return(RedirectToAction("ShowAnnouncement", "Announcement", new { editingCandidate.Id }));
            }
            repositoryResult = _userRepository.FindUser(User.Identity.Name);
            if (repositoryResult.Status != ActionStatus.Success)
            {
                MessageForClient(repositoryResult.Status, $"Не найден авторизованный пользователь ({User.Identity.Name}).");
                return(RedirectToAction("Index", "Home"));
            }
            var updatingCandidate = _mapper.Map <MyCandidate, CandidateBase>(editingCandidate);

            updatingCandidate.LastEditor = repositoryResult.Entity.First() as UserBase;
            if (imageFile != null)
            {
                byte[] buf = new byte[imageFile.ContentLength];
                imageFile.InputStream.Read(buf, 0, imageFile.ContentLength);
                updatingCandidate.Photo = buf;
            }
            repositoryResult = _announcementRepository.UpdateAnnouncement(updatingCandidate);
            MessageForClient(repositoryResult.Status, repositoryResult.Message);

            return(repositoryResult.Status == ActionStatus.Success
                ? RedirectToAction("ShowAnnouncement", "Announcement", new { (repositoryResult.Entity.First() as CandidateBase).Id })
                : RedirectToAction("Index", "Home"));
        }