} // NoticesController // Получение списка элементов public async Task <IActionResult> Index(bool ajaxLoad) { var user = await _userManager.FindByNameAsync(User.Identity.Name); var viewModel = new IndexViewModel( await _proposalRepository.GetProposals(), await _requisitionRepository.GetRequisitions(), await _messageRepository.GetMessages(_userManager), await _readedNoticeRepository.GetUserReadedNoticesCounter(user.Id)); if (!ajaxLoad) { return(View(viewModel)); } return(PartialView(viewModel)); } // Index
} // Index // Получение детальной информации об элементе public async Task <IActionResult> Details(int id, bool ajaxLoad, string connectionId, string previousUrl) { try { var requisition = await _requisitionRepository.GetRequisition(id); if (requisition == null) { throw new Exception(); } var viewModel = new DetailsViewModel( requisition, await _proposalRepository.GetProposals(requisition.Machine)); if (!ajaxLoad) { return(View(viewModel)); } return(PartialView(viewModel)); } catch { await _hub.Clients.Client(connectionId).SendAsync("Error", Messages.downloadErrorMessage); if (previousUrl == null) { return(RedirectToAction("Index", new { ajaxLoad = true })); } return(Redirect(previousUrl + "?ajaxLoad=true")); } // try-catch } // Details
public void IsNotNullGetProposalsTest() { var data = _repository.GetProposals(1); Assert.IsNotNull(data); Assert.AreEqual(data[0].User.UserName, "AKowalski"); }
public async Task <IActionResult> Index(bool ajaxLoad) { var viewModel = new IndexViewModel(await _proposalRepository.GetProposals()); if (!ajaxLoad) { return(View(viewModel)); } return(PartialView(viewModel)); } // Index
public async Task <List <ProposalDTO> > GetProposals() { try { var allProposals = await _proposalRepository.GetProposals(); allProposals = allProposals.Where(x => x.Activa == true).ToList(); //traigo solo las que estan activas (no eliminadas) return(allProposals); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Get() { try { List <object> result = new List <object>(); var username = User?.Identity?.Name; var proposals = (await _repository.GetProposals()).Where(x => x.Candidate.UserName == username || x.Advert.Creator.UserName == username).OrderByDescending(proposal => proposal.Id); var user = (await _userManager.FindByNameAsync(username)); foreach (var proposal in proposals) { bool isMine = user.Id == proposal.Advert.CreatorId, showInitialButtons = proposal.Status == ProposalStatus.Pending; User feedBackProfileUser = isMine ? proposal.Candidate : proposal.Advert.Creator; bool canWriteFeedBack = proposal.Status == ProposalStatus.Completed && !(await UserWroteFeedBack(user.Id, proposal.Id)); result.Add(new { id = proposal.Id, value = proposal.Value.ToString("N2"), advert = new AdvertViewModel(proposal.Advert), status = proposal.Status == 0 ? ProposalStatus.Pending : proposal.Status, isMine, canApprove = showInitialButtons, canRefuse = showInitialButtons, canSuspend = showInitialButtons, canStart = proposal.Status == ProposalStatus.Accepted, canComplete = proposal.Status == ProposalStatus.Active, canWriteFeedBack, feedbackProfileId = feedBackProfileUser.UserInfoId }); } return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IList <ProposalDto> GetProposals(int id) { var proposals = _proposalRepository.GetProposals(id); return(_mapper.Map <IList <ProposalDto> >(proposals)); }
public ResponseViewModel GetAllProposals() { var result = _proposalRepository.GetProposals().Select(_mapper.Map <Proposal, ProposalViewModel>); return(Ok(result)); }