Code

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

using BrandMaster.

Models;
using BrandMaster.Views.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using ImageMagick;
using System.IO;
using System.Windows.Media;
using System.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.ComponentModel;
using System.Diagnostics;
using PdfSharp.Pdf.IO;
using PdfSharp;
using System.Security.Policy;
using System.Web;
using MigraDoc;
using System.Net.Http.Headers;
using Amazon.S3.Transfer;
using Amazon.S3;
using Amazon;
using Amazon.S3.IO;
using System.Web.UI.WebControls;
using System.Threading.Tasks;
using System.Data.Entity.Core.Objects;
using Amazon.S3.Model;
using System.Runtime.Serialization;
using System.Collections;

namespace BrandMaster.Controllers
{

// [System.Web.Http.Authorize]
[System.Web.Http.Httpget]
[System.Web.Http.Route("api/check")]
public class CheckController : ApiController
{
#region Bindingbycheckbox
public HttpResponseMessage GettingcheckboxesImages(string checkbox)
{
PdfDocument doc = new PdfDocument();
using (CheckFranchiseEntities dc = new CheckFranchiseEntities())
{
byte[] image = null;
string allKeyString = checkbox.Substring(checkbox.IndexOf("?") +
1);
string[] allKeyAndValue = allKeyString.Split(',');
List<GetImagesinPdf> listOfClass_mrg = new List<GetImagesinPdf>();
{
for (var i = 0; i < allKeyAndValue.Length; i++)
{
int item = Convert.ToInt32(allKeyAndValue[i]);
GetImagesinPdf obj = new GetImagesinPdf();
{
var u = (from obj1 in dc.tbl_BrandMaster
join obj2 in dc.tbl_GraphicMaster on obj1.VAImageId
equals obj2.id
where obj1.id == item
select new
{
ImageId = obj1.VAImageId,
path_img = obj2.FileName,
Awsimage = ""
}).ToList()
.Select(x => new AwsImageClass()
{
AwsImage =
AwsClass.GetUrlAwsS3("vibcarevisualaids", x.path_img),
// imageId = Convert.ToString(x.ImageId)
}).ToList();

if (u.Count() == 0)
{
List<AwsImageClass> listclass = new
List<AwsImageClass>();
u.Add(new AwsImageClass { path = null, path_img = null,
AwsImage = null, });
}
for(int j=0; j < allKeyAndValue.Length; j++)
{
if(u[i].imageId == u[j].imageId)
{
listOfClass_mrg.Add(obj);
}
}
}
// var c = listOfClass_mrg.Distinct().ToList();
}
}

List<GetImagesinPdf> listOfClass_mrg3 = new


List<GetImagesinPdf>();
{
for (int i = 0; i < listOfClass_mrg.Count(); i++)
{
GetImagesinPdf obj = new GetImagesinPdf();
{
obj.BAwsPath = listOfClass_mrg[i].BAwsPath;
{
using (WebClient client = new WebClient())
{
var request =
(System.Net.HttpWebRequest)System.Net.WebRequest.Create(obj.BAwsPath);
var response =
(System.Net.HttpWebResponse)request.GetResponse();
if (request.HaveResponse)
{
if (response.StatusCode ==
System.Net.HttpStatusCode.OK)
{
Stream receiveStream =
response.GetResponseStream();
using (BinaryReader br = new
BinaryReader(receiveStream))
{
image = br.ReadBytes(50000000);
{
using (MemoryStream ms =
new MemoryStream((image)))
{
PdfPage pdfPage = new
PdfPage();
var opage = new
PdfPage();
doc.Pages.Add(opage);
XGraphics xgr =
XGraphics.FromPdfPage(opage);
XImage img =
XImage.FromStream(ms);
double height =
pdfPage.Width / img.PixelWidth * img.PixelHeight;
xgr.DrawImage(img, 0,
0, pdfPage.Width, height);

}
//save to destination file
// br.Close();
}
}
}
}
}
}
}
}
}
}
string DateTimeFormat = "yyyy''MM''dd'T'HH''mm''ss.fffffffK";
var DateValue = DateTime.Now.ToString(DateTimeFormat);
string newname = String.Format("DateValue" + ".pdf");
// string path =
Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory());
string projectDirectory =
Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Pers
onal));
//doc.Save((projectDirectory + "\\Image2.pdf");
doc.Save(projectDirectory + "//" + newname);
doc.Close();
using (TransferUtility transferUtility = new
Amazon.S3.Transfer.TransferUtility("AKIAJWK5MRYUNKDTWCZQ",
"HT5c8npdGtRVXPsbIFGkZ8WGLzDhWUf+kM+SoXA1", RegionEndpoint.APSouth1))
{
TransferUtilityUploadRequest uploadRequest = new
TransferUtilityUploadRequest
{
BucketName = "vibcaretemp",
FilePath = projectDirectory + "//" + newname,
};
transferUtility.Upload(uploadRequest);
}
List<GetImagesinPdf> listOfClass_mrg2 = new List<GetImagesinPdf>();
{
GetImagesinPdf obj = new GetImagesinPdf();
{
obj.BSaveFile = AwsClass.GetUrlAwsS3("vibcaretemp",
newname);
}
listOfClass_mrg2.Add(obj);
}
#endregion

#region return list


try
{
var retStr = new HttpResponseMessage(HttpStatusCode.OK);
HttpResponseMessage response;
response = Request.CreateResponse(HttpStatusCode.OK,
listOfClass_mrg2, Configuration.Formatters.JsonFormatter);
return response;
}
catch (Exception)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
}
}
}

#endregion

You might also like