Ejemplo n.º 1
0
        public void UpdateMainEntries(IEnumerable <MainEntry> entries)
        {
            var                  titleMaps     = _workbook.ReadTitleMapRules();
            TextInfo             textInfo      = Thread.CurrentThread.CurrentCulture.TextInfo;
            PictureSetRepository picRepository = new PictureSetRepository();

            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                dataContext.MaterializeAttributes = true;

                foreach (MainEntry entry in entries)
                {
                    try
                    {
                        Item item = dataContext.Items.Include("EbayListingItems").Include("AmznListingItems").SingleOrDefault(p => p.ItemLookupCode.Equals(entry.Sku));

                        if (item == null)
                        {
                            entry.Message = "sku not found";
                            continue;
                        }

                        entry.Brand     = item.SubDescription1;
                        entry.ClassName = item.ClassName;
                        entry.Qty       = item.QtyAvailable;
                        entry.Cost      = item.Cost;

                        entry.Department  = item.DepartmentName;
                        entry.Category    = item.CategoryName;
                        entry.Gender      = item.SubDescription3;
                        entry.Color       = item.SubDescription2;
                        entry.Notes       = item.Notes;
                        entry.Price       = item.Price;
                        entry.Location    = item.BinLocation;
                        entry.Cost        = item.Cost;
                        entry.Qty         = item.QtyAvailable;
                        entry.Description = item.Description;
                        entry.UPC         = item.GTIN;

                        var pics = picRepository.GetPictures(entry.Brand, new List <string>()
                        {
                            entry.Sku
                        });

                        entry.PictureCount = pics.Count;

                        var titleMap = titleMaps.SingleOrDefault(p => p.Department.Equals(item.DepartmentName) && p.Category.Equals(item.CategoryName));

                        if (titleMap == null)
                        {
                            titleMap     = new TitleMapRule();
                            titleMap.Map = "";
                        }

                        string description = item.Description;
                        string dims        = string.Empty;

                        foreach (var attribute in item.Dimensions)
                        {
                            description = description.Replace(" " + attribute.Value.Value + " ", "");
                            dims       += attribute.Value.Value + " ";
                        }

                        entry.TitleFormula = textInfo.ToTitleCase((entry.Brand + " " + titleMap.Map + " Size " + dims + description).ToLower());

                        var ebayHistory = string.Join(" ", item.EbayListingItems.Where(p => p.Listing.Status.Equals(EbayMarketplace.STATUS_ACTIVE)).Select(p => p.ToString()));
                        var amznHistory = string.Join(" ", item.AmznListingItems.Where(p => p.IsActive).Select(p => p.ToString()));

                        entry.Status = ebayHistory + " " + amznHistory;

                        if (item.EbayListingItems.Where(w => w.Listing.IsVariation.HasValue && !w.Listing.IsVariation.Value).Count() > 0)
                        {
                            EbayListingItem listingItem = item.EbayListingItems.Single(p => p.ID == item.EbayListingItems.Where(w => w.Listing.IsVariation.HasValue && !w.Listing.IsVariation.Value).Max(s => s.ID));
                            entry.Title           = listingItem.Listing.Title;
                            entry.FullDescription = listingItem.Listing.FullDescription;
                        }
                        else if (dataContext.bsi_quantities.Any(p => p.itemLookupCode.Equals(entry.Sku)))
                        {
                            var postDetails = dataContext.bsi_quantities.Where(p => p.itemLookupCode.Equals(entry.Sku));

                            int lastPostDetailID = postDetails.Max(p => p.id);

                            bsi_quantities postDetail = postDetails.Single(p => p.id == lastPostDetailID);

                            entry.Title           = postDetail.title;
                            entry.FullDescription = postDetail.bsi_posts.bsi_posting.fullDescription;
                        }
                    }
                    catch (Exception e)
                    {
                        entry.Message = e.Message;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private string CreateHtmlTable(IEnumerable <PrintEntry> entries)
        {
            StringBuilder table = new StringBuilder();

            string style = @"<style> @media print{thead{display: table-header-group;}} img { height:100px; max-width:100px; width: expression(this.width > 500 ? 500: true);} td { text-align: center;} .input { padding: 50px; }  </style>";

            table.AppendFormat(@"<html><head>{0}</head><body><table border=""2"">", style);

            PictureSetRepository picRepository = new PictureSetRepository();

            var classGroups = entries.GroupBy(p => p.ClassName).OrderBy(p => p.Key);

            table.Append("<thead><tr><th>Picture</th><th>Brand</th><th>Gender</th><th>Sku</th><th>Qty</th><th>Cost</th><th>UPC</th><th>Active</th><th>ORI</th><th>STG</th><th>OMS</th><th>LCS</th></tr></thead><tbody>");

            foreach (var classGroup in classGroups)
            {
                var pics = picRepository.GetPictures(classGroup.First().Brand, classGroup.Select(p => p.Sku).ToList());

                var mainPic = pics.OrderBy(p => p.Name).FirstOrDefault();

                bool hasImage = false;

                string rowSpan = classGroup.Count().ToString();

                foreach (PrintEntry entry in classGroup.OrderBy(p => p.Sku))
                {
                    table.Append("<tr>");

                    if (!hasImage)
                    {
                        if (mainPic != null)
                        {
                            table.AppendFormat(@"<td rowspan=""{1}""><img src=""{0}""></td>", mainPic.Path, rowSpan);
                        }
                        else
                        {
                            table.AppendFormat(@"<td rowspan=""{1}""><img src=""{0}""></td>", string.Empty, rowSpan);
                        }


                        table.AppendFormat(@"<td rowspan=""{1}"">{0}</td>", entry.Brand, rowSpan);
                        table.AppendFormat(@"<td rowspan=""{1}"">{0}</td>", entry.Gender, rowSpan);
                    }


                    table.AppendFormat("<td>{0}</td>", entry.Sku);
                    table.AppendFormat("<td>{0}</td>", entry.Qty);
                    table.AppendFormat("<td>{0:C}</td>", entry.Cost);



                    table.AppendFormat("<td>{0}</td>", string.IsNullOrEmpty(entry.UPC) ? "No" : "Yes");

                    table.AppendFormat(@"<td class=""history"">{0}</td>", entry.Active);


                    if (!hasImage)
                    {
                        table.AppendFormat(@"<td class=""input"" rowspan=""{0}"">     </td>", rowSpan);
                        table.AppendFormat(@"<td class=""input""  rowspan=""{0}"">     </td>", rowSpan);
                        table.AppendFormat(@"<td class=""input""  rowspan=""{0}"">     </td>", rowSpan);
                        table.AppendFormat(@"<td class=""input""  rowspan=""{0}"">     </td>", rowSpan);

                        hasImage = true;
                    }

                    table.Append("</tr>");
                }
            }

            table.Append("</tbody></table></body></html>");

            return(table.ToString());
        }
Ejemplo n.º 3
0
        public void AddListing(ListingDto listingDto)
        {
            var pics = _picSetRepository.GetPictures(listingDto.Brand, listingDto.Items.Select(p => p.Sku).ToList()).Take(4).OrderBy(p => p.Name);

            if (pics.Count() == 0)
            {
                throw new InvalidOperationException("picture required");
            }

            foreach (var pic in pics)
            {
                listingDto.PicUrls.Add(pic.Path.Replace("\\", "/").Replace(LOCAL_PICTURE_ROOT, S3_PICTURE_URL_ROOT));
            }

            HttpWebRequest request = WebRequest.CreateHttp("https://api.bonanza.com/api_requests/secure_request");

            request.Headers.Add("X-BONANZLE-API-DEV-NAME", "vWhzo4w8l7sKDUT");
            request.Headers.Add("X-BONANZLE-API-CERT-NAME", "YOL7ZWkbcBJGKTI");

            request.ContentType = "application/json";

            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);

            request.Method = "POST";

            dynamic addFixedPriceItemRequest = new ExpandoObject();

            addFixedPriceItemRequest.requesterCredentials = new ExpandoObject();
            addFixedPriceItemRequest.requesterCredentials.bonanzleAuthToken = _marketplace.Token;
            addFixedPriceItemRequest.item = MapToBonanzaDto(listingDto, true, true);

            dynamic jsonPayload = new ExpandoObject();

            jsonPayload.addFixedPriceItemRequest = addFixedPriceItemRequest;

            byte[] contentBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(jsonPayload));

            request.ContentLength = contentBytes.Length;

            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(contentBytes, 0, contentBytes.Length);
            }

            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                string output = null;

                using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    output = sr.ReadToEnd();
                }

                dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(output);

                string ack = result.ack;

                if (ack.Equals("Success"))
                {
                    string itemID       = result.addFixedPriceItemResponse.itemId;
                    string sellingState = result.addFixedPriceItemResponse.sellingState;

                    listingDto.Code = itemID;

                    Persist(listingDto, sellingState);
                }
            }
            catch (WebException e)
            {
                using (WebResponse response = e.Response)
                {
                    var httpResponse = (HttpWebResponse)response;

                    using (Stream data = response.GetResponseStream())
                    {
                        StreamReader sr = new StreamReader(data);
                        throw new Exception(sr.ReadToEnd());
                    }
                }
            }
        }