예제 #1
0
 public ImageData Add(ImageData image)
 {
     Guid newId = Guid.NewGuid(); //.GenerateNewId();
     image.id = newId;
     _imageRepository.Collection.Save(image);
     return Get(newId);
 }
예제 #2
0
        public ImageData AddImage(ImageData image, Guid productId)
        {
            var query = Query.EQ("_id", productId.ToString());
            ReviewableData toUpdate = _reviewableRepository.Collection.FindOne(query);

            List<string> imageIds = toUpdate.images.ToList();
            //imageIds.Add(image.id.ToString());

            //save the image
            Guid newId = Guid.NewGuid();
            image.id = newId;
            imageIds.Add(image.id.ToString());
            _imagesRepository.Collection.Save(image);
            //save the product
            toUpdate.images = imageIds.ToArray();
            _reviewableRepository.Collection.Save(toUpdate);

            //go fetch the image
            var query2 = Query.EQ("_id", newId.ToString());
            image =_imagesRepository.Collection.FindOne(query);
            return image;
        }
예제 #3
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            SqlConnection conn = null;
            SqlDataReader dr = null;

            try
            {
                ReviewableRepository rr = new ReviewableRepository();
                conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DataServices"].ConnectionString);
                conn.Open();

                SqlCommand cmd = new SqlCommand("Select * from [dbo].[Company]", conn);
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    ReviewableData r = new ReviewableData();

                    r.name = dr.GetString(1);
                    r.reviewableType = "business";
                    r.images = new string[0];
                    r.issuerCountryCode = "en_us";
                    r.issuerCountry = "United States";
                    r.createdDate = DateTime.UtcNow;

                    rr.Add(r, Guid.Empty);
                }
                dr.Close();

                IEnumerable<ReviewableData> bizs = rr.Get();
                foreach (ReviewableData biz in bizs)
                {
                    SqlDataReader dr2 = null;
                    string query = @"SELECT top 1 i.uid, i.data, i.fileType, lkift.FileTypeName as imageTypeName, c.Name, 1 as Type, i.dateCreated FROM Image i
                        INNER JOIN lk_Image_FileType lkift on lkift.id = i.fileType
                        INNER JOIN Company_Image ci on i.uid = ci.ImageId
                        INNER JOIN Company c on c.id = ci.CompanyId
                        WHERE c.name = '" + biz.name + "' ORDER by i.dateCreated DESC";
                    SqlCommand cmd2 = new SqlCommand(query, conn);

                    dr2 = cmd2.ExecuteReader();
                    while (dr2.Read())
                    {
                        ImageData l = new ImageData();
                        Guid newId = Guid.NewGuid();
                        l.id = newId;
                        Object data = dr2.GetValue(1);
                        l.data = (byte[])data;

                        l.fileType = dr2.GetString(3);
                        l.category = "company";
                        l.description = dr2.GetValue(4).ToString();
                        l.type = dr2.GetInt32(5);
                        l.dateCreated = dr2.GetDateTime(6);
                        //now add it to the db
                        l = rr.AddImage(l, biz.id);
                    }
                    dr2.Close();
                }
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
예제 #4
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            SqlConnection conn = null;
            SqlDataReader dr = null;

            try
            {
                ReviewableRepository pr = new ReviewableRepository();

                conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DataServices"].ConnectionString);
                conn.Open();

                SqlCommand cmd = new SqlCommand("GetProductsByName", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@name", "");
                cmd.Parameters.AddWithValue("@userId", 1);

                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    ReviewableData prod = new ReviewableData();
                    prod.name = dr.GetString(1);
                    if (dr.GetValue(2) != DBNull.Value)
                        prod.description = dr.GetString(2);
                    if (dr.GetValue(3) != DBNull.Value && dr.GetString(3).Trim().Length != 0)
                        prod.outsideCode = dr.GetString(3);
                    if (dr.GetValue(4) != DBNull.Value && dr.GetString(4).Trim() != "None")
                        prod.outsideCodeType = dr.GetString(4).Trim();
                    if (dr.GetValue(5) != DBNull.Value)
                        prod.issuerCountryCode = "en_us"; // dr.GetString(5);
                    if (dr.GetValue(6) != DBNull.Value)
                        prod.issuerCountry = dr.GetString(6);
                    //if (dr.GetValue(7) != DBNull.Value)
                        //prod.manufacturerid = dr.GetString(7);
                    //if (dr.GetValue(8) != DBNull.Value)
                        //prod.modelNum = dr.GetString(8);

                    if (dr.GetValue(10) != DBNull.Value)
                    {
                        ReviewableData biz = pr.GetByName(dr.GetString(10), Guid.Empty).First();
                        prod.parentReviewableId = biz.id;
                        prod.parentName = biz.name;
                    }
                    prod.reviewableType = "product";
                    prod.images = new string[0];
                    prod.createdDate = DateTime.UtcNow;
                    pr.Add(prod, Guid.Empty);

                }
                dr.Close();

                IEnumerable<ReviewableData> prods = pr.Get();
                foreach (ReviewableData prod in prods)
                {
                    SqlDataReader dr2 = null;
                    string query = @"SELECT top 1 i.uid, i.data, i.fileType, lkift.FileTypeName as imageTypeName, p.Name, 2 as Type, i.dateCreated FROM Image i
                        INNER JOIN lk_Image_FileType lkift on lkift.id = i.fileType
                        INNER JOIN Product_Image pi on i.uid = pi.ImageId
                        INNER JOIN Product p on p.id = pi.ProductId
                        WHERE p.name = '" + prod.name + "' ORDER by i.dateCreated DESC";
                    SqlCommand cmd2 = new SqlCommand(query, conn);

                    dr2 = cmd2.ExecuteReader();
                    while (dr2.Read())
                    {
                        ImageData l = new ImageData();
                        Guid newId = Guid.NewGuid(); //.GenerateNewId();
                        l.id = newId;
                        Object data = dr2.GetValue(1);
                        l.data = (byte[])data;

                        l.fileType = dr2.GetString(3);
                        l.category = "tile";
                        l.description = dr2.GetValue(4).ToString();
                        l.type = dr2.GetInt32(5);
                        l.dateCreated = dr2.GetDateTime(6);

                        pr.AddImage(l, prod.id);

                    }
                    dr2.Close();

                }
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }