public async Task <VotingResponse> Update(VotingRequest request) { VotingResponse response = new VotingResponse(); try { Voting voting = new Voting(); voting.VotingId = request.VotingID; voting.VotingName = request.VotingName; voting.VotingDescription = request.VotingDescription; voting.DueDate = request.DueDate; voting.CategoryId = request.CategoryID; voting.Modified = DateTime.Now; voting.ModifiedBy = request.CurrentLogin; if (await iVoting.Update <Voting>(voting)) { return(response); } response.Message = "Failed to Update Voting"; response.IsSuccess = false; } catch (Exception ex) { response.Message = "Something Error in Our System : " + ex.Message; response.IsSuccess = false; } return(response); }
public async Task <IActionResult> GetAll([FromBody] VotingRequest request) { try { return(Ok(await facade.GetAll())); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <VotingResponse> GetByID(VotingRequest request) { VotingResponse response = new VotingResponse(); try { response.Voting = await iVoting.GetByID <VotingViewModel>(request.VotingID); } catch (Exception ex) { response.Message = "Something Error in Our System : " + ex.Message; response.IsSuccess = false; } return(response); }
public async Task <ActionResult> VoteForSupplier(VotingRequest votingRequest) { if (!votingRequest.BidId.IsValidId() || !votingRequest.BuyerId.IsValidId() || !votingRequest.VotedSupplierId.IsValidId()) { return(this.StatusCode(StatusCodes.Status400BadRequest, $"one of the follwing: bidId: {votingRequest.BidId}, buyerId: {votingRequest.BuyerId} supplierId: {votingRequest.VotedSupplierId} are not legal id")); } Response response = await this.bidsManager.VoteForSupplier(votingRequest).ConfigureAwait(false); if (response.IsOperationSucceeded) { return(this.StatusCode(StatusCodes.Status200OK, response.SuccessOrFailureMessage)); } return(this.StatusCode(StatusCodes.Status405MethodNotAllowed, response.SuccessOrFailureMessage)); }
public async Task <VotingResponse> Delete(VotingRequest request) { VotingResponse response = new VotingResponse(); try { if (await iVoting.Delete(request.VotingID)) { return(response); } response.Message = "Failed to Delete Voting"; response.IsSuccess = false; } catch (Exception ex) { response.Message = "Something Error in Our System : " + ex.Message; response.IsSuccess = false; } return(response); }
public async Task <IActionResult> Add([FromBody] VotingRequest request) { try { authHelper.IsLogin(ref CurrentLogin, ref response, HttpContext.User.Identity as ClaimsIdentity); if (response.IsSuccess) { request.CurrentLogin = CurrentLogin; if (request.VotingID > 0) { return(Ok(await facade.Update(request))); } else { return(Ok(await facade.Add(request))); } } return(Ok(response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <Response> VoteForSupplier(VotingRequest votingRequest) { BidEntity bid = await _context.Bids.Where(b => b.Id == votingRequest.BidId).Include(b => b.CurrentProposals).Include(b => b.CurrentParticipancies).FirstOrDefaultAsync().ConfigureAwait(false); if (bid == null) { return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = BidNotFoundFailString }); } ParticipancyEntity participancy = bid.CurrentParticipancies.Where(p => p.BuyerId == votingRequest.BuyerId).FirstOrDefault(); if (participancy == null) { return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = $"Buyer {votingRequest.BuyerId} is not part of the bids buyers." }); } else if (participancy.HasVoted) { // TODO enable change after vote return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = $"Buyer {votingRequest.BuyerId} has already voted" }); } SupplierProposalEntity proposal = bid.CurrentProposals.Where(p => p.SupplierId == votingRequest.VotedSupplierId).FirstOrDefault(); if (proposal == null) { return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = $"no proposal for supplier: {votingRequest.VotedSupplierId} has found for the bid." }); } participancy.HasVoted = true; proposal.Votes += 1; try { _context.Set <ParticipancyEntity>().Update(participancy); _context.Set <SupplierProposalEntity>().Update(proposal); await _context.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message }); } return(new Response() { IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage() }); }
public Task <Response> VoteForSupplier(VotingRequest votingRequest) { throw new NotImplementedException(); }
public HttpResponseMessage Post([FromBody] VotingRequest votingRequest) { if (votingRequest == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var response = new HttpResponseMessage(HttpStatusCode.OK); var contentFolder = HttpContext.Current.Server.MapPath("~/Content"); var pdfFileTemplate = contentFolder + @"/VotingRequestDocument.pdf"; using (var existingFileStream = new FileStream(pdfFileTemplate, FileMode.Open)) { using (var newPdfFileStream = new MemoryStream()) { var xCord = 296; var yCord = 615; var pdfReader = new PdfReader(existingFileStream); var stamper = new PdfStamper(pdfReader, newPdfFileStream); var content = stamper.GetOverContent(1); content.BeginText(); content.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, false), 12f); //reduced font size to fit birth place and date. This encoding does not support Cyrillic content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.FirstLastName, xCord, yCord, 0); yCord -= 23; //first we will put the birth date, and then the birth place content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.BirthDate, xCord, yCord, 0); xCord += 65; //Move the input so you don't cover the date field content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.BirthPlace, xCord, yCord, 0); xCord -= 65; //return the input to the left part of the form yCord -= 24; content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.Gender, xCord, yCord, 0); yCord -= 22; content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.ParentName, xCord, yCord, 0); yCord -= 22; float tempXCoord = xCord + 5; if (votingRequest.PersonalId != null) { foreach (char number in votingRequest.PersonalId) { content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, number.ToString(), tempXCoord, yCord, 0); tempXCoord += 17.5f; } } yCord -= 28; content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.PassportId, xCord, yCord, 0); yCord -= 35; content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.HomeCountryAddress, xCord, yCord, 0); yCord -= 38; content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.TemporaryAddress, xCord, yCord, 0); yCord -= 35; content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.ForeignCountryName, xCord, yCord, 0); yCord -= 38; content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.ForeignCountryAddress, xCord, yCord, 0); yCord -= 48;//Check if there is a preference for the voting place. If not, go with the default embassy/consulate if (votingRequest.PrefferedVotingLocation != null) { content.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, false), 12f); content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.PrefferedVotingLocation, xCord, yCord, 0); } else { if (votingRequest.VotingLocation != null) { content.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, false), 12f); content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.VotingLocation.Split('|').FirstOrDefault(), xCord, yCord, 0); } } content.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, false), 14f); yCord -= 40; content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.CurrentLocation, xCord - 163, yCord, 0); content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, DateTime.Now.ToString("dd. MM. yyyy."), xCord - 60, yCord, 0); yCord -= 55; var bytes = Convert.FromBase64String(votingRequest.Signature.Split(',')[1]); using (var rawImage = new MemoryStream(bytes)) { Image image = Image.GetInstance(ImageHelper.ScaleImage(rawImage, 150, 150), ImageFormat.Png); image.SetAbsolutePosition(xCord + 85, yCord); content.AddImage(image); } content.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, false), 12f); yCord -= 23; content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.PhoneNumber, xCord + 50, yCord, 0); yCord -= 12; content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, votingRequest.Email, xCord + 50, yCord, 0); content.EndText(); stamper.Close(); pdfReader.Close(); response.Content = new ByteArrayContent(newPdfFileStream.GetBuffer()); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentDisposition.FileName = "Zahtev za glasanje 2020.pdf"; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); } } return(response); }
public Voting() { facade = new VotingFacade(connectionString); request = new VotingRequest(); }