コード例 #1
0
        // GET: api/QR/5
        /// <summary>
        /// wygeneruj kod qr dla existinigproduct
        /// </summary>
        /// <param name="id">existingproduct id</param>
        /// <returns></returns>
        public HttpResponseMessage GetQR(int id)
        {
            var existingProduct = db.ExistingProducts.Find(id);

            if (existingProduct == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.Entry(existingProduct).Reference(e => e.QR).Load();

            var qr = existingProduct.QR;

            if (qr == null)
            {
                qr = new QR
                {
                    ExistingProductId = existingProduct.Id,
                    ExistingProduct   = existingProduct
                };
                db.Entry(existingProduct).Reference(e => e.Product).Load();
                db.Entry(existingProduct.Product).Reference(p => p.Company).Load();
                qr.UpdateQR();
                db.QRs.Add(qr);
                db.SaveChanges();
            }

            var response = Request.CreateResponse();

            response.Content = new StreamContent(new MemoryStream(qr.Content));
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");

            return(response);
        }