Exemple #1
0
    private void Awake()
    {
        cardOutput    = GetComponent <CardOutput>();
        cardAnimation = GetComponent <CardAnimation>();

        cardController = new CardController(this, cardAnimation);
    }
        public static CardOutput GetDTO(this Card card)
        {
            if (card == null)
            {
                return(null);
            }

            var columnOutput = new CardOutput
            {
                Id        = card.Id,
                Text      = card.Text,
                ProjectId = card.Column.Project.Id,
                SprintId  = card.Column.Sprint.Id
            };

            return(columnOutput);
        }
        public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context,
                                                    Encoding selectedEncoding)
        {
            CardOutput    card    = (CardOutput)context.Object;
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("BEGIN:VCARD");
            builder.AppendLine("VERSION:4.0");
            builder.Append("N:").AppendLine(card.N);
            builder.Append("FN:").AppendLine(card.Name);
            if (card.Uid != 0)
            {
                builder.Append("UID:").AppendLine(card.Uid + "");
                builder.Append("ORG:").AppendLine("Southern Hemisphere Institute of Technology");
            }
            else
            {
                builder.Append("UID:").AppendLine("");
                builder.Append("ORG:").AppendLine("");
            }

            builder.Append("EMAIL;TYPE=work:").AppendLine(card.Email);
            builder.Append("TEL:").AppendLine(card.Tel);
            builder.Append("URL:").AppendLine(card.url);
            builder.Append("CATEGORIES:").AppendLine(card.Categories);
            builder.Append("PHOTO;ENCODING=BASE64;TYPE=").Append(card.PhotoType)
            .Append(":").AppendLine(card.Photo);
            builder.Append("LOGO;ENCODING=BASE64;TYPE=").Append(card.LogoType)
            .Append(":").AppendLine(card.LogoImg);
            builder.AppendLine("END:VCARD");
            string outString = builder.ToString();

            byte[] outBytes = selectedEncoding.GetBytes(outString);
            var    response = context.HttpContext.Response.Body;

            return(response.WriteAsync(outBytes, 0, outBytes.Length));
        }
        public ActionResult GetCard(int id)
        {
            Staff  staff   = _repository.GetCard(id);
            string path    = Directory.GetCurrentDirectory();
            string shitDir = Path.Combine(path, "SHITdataXY-569504563");
            string imgPath = Path.Combine(shitDir, "StaffPhotos");

            if (staff != null)
            {
                string      fileName1 = Path.Combine(imgPath, id + ".png");
                string      fileName2 = Path.Combine(imgPath, id + ".jpg");
                string      fileName3 = Path.Combine(imgPath, id + ".gif");
                string      fileName = "";
                string      photoString, photoType;
                ImageFormat imageFormat;
                if (System.IO.File.Exists(fileName1))
                {
                    fileName = fileName1;
                }
                else if (System.IO.File.Exists(fileName2))
                {
                    fileName = fileName2;
                }
                else if (System.IO.File.Exists(fileName3))
                {
                    fileName = fileName3;
                }
                else
                {
                    return(NotFound());
                }

                Image image = Image.FromFile(fileName);
                imageFormat = image.RawFormat;
                image       = ImgHelper.Resize(image, new Size(100, 100), out photoType);
                photoString = ImgHelper.ImageToString(image, imageFormat);

                CardOutput cardOut = new CardOutput();
                cardOut.N         = staff.LastName + ";" + staff.FirstName + ";;" + staff.Title + ";";
                cardOut.Name      = staff.Title + " " + staff.FirstName + " " + staff.LastName;
                cardOut.Uid       = staff.Id;
                cardOut.Email     = staff.Email;
                cardOut.Tel       = staff.Tel;
                cardOut.url       = staff.url;
                cardOut.Photo     = photoString;
                cardOut.PhotoType = photoType;

                string      logoString, logoType;
                ImageFormat logoFormat;
                string      logofile = Path.Combine(imgPath, "logo.png");
                Image       logoimg  = Image.FromFile(logofile);
                logoFormat       = logoimg.RawFormat;
                logoimg          = ImgHelper.Resize(logoimg, new Size(100, 100), out logoType);
                logoString       = ImgHelper.ImageToString(logoimg, logoFormat);
                cardOut.LogoImg  = logoString;
                cardOut.LogoType = logoType;

                cardOut.Categories = Helper.CategoryHelper.Filter(staff.Research);
                Response.Headers.Add("Content-Type", "text/vcard");
                return(Ok(cardOut));
            }
            else
            {
                CardOutput cardOut = new CardOutput();
                cardOut.N         = ";" + ";;" + ";";
                cardOut.Name      = "";
                cardOut.Uid       = 0;
                cardOut.Email     = "";
                cardOut.Tel       = "";
                cardOut.url       = "";
                cardOut.Photo     = "";
                cardOut.PhotoType = "UNKNOWN";

                string      logoString, logoType;
                ImageFormat logoFormat;
                string      logofile = Path.Combine(imgPath, "logo.png");
                Image       logoimg  = Image.FromFile(logofile);
                logoFormat       = logoimg.RawFormat;
                logoimg          = ImgHelper.Resize(logoimg, new Size(100, 100), out logoType);
                logoString       = ImgHelper.ImageToString(logoimg, logoFormat);
                cardOut.LogoImg  = logoString;
                cardOut.LogoType = logoType;

                cardOut.Categories = "";
                Response.Headers.Add("Content-Type", "text/vcard");
                return(Ok(cardOut));
            }
        }