예제 #1
0
 private static void UpdateUserActivity()
 {
     using (var dataContext = new VincontrolEntities())
     {
         foreach (var item in dataContext.UserDealerActivities)
         {
             if (string.IsNullOrEmpty(item.Detail))
             {
                 continue;
             }
             var resultString        = item.Detail.Split(';');
             var usernameString      = resultString[0];
             var usernameStringArray = usernameString.Split(':');
             if (usernameStringArray.Length > 1)
             {
                 var username       = usernameStringArray[1].Trim();
                 var firstOrDefault = dataContext.Users.FirstOrDefault(i => i.UserName == username);
                 item.UserName = username;
                 item.Email    = GetContent(resultString[1]).Trim();
                 item.Phone    = GetContent(resultString[2]).Trim();
                 item.Role     = GetContent(resultString[3]).Trim();
                 if (firstOrDefault != null)
                 {
                     item.UserId = firstOrDefault.UserId;
                 }
             }
         }
         dataContext.SaveChanges();
     }
 }
예제 #2
0
 private void CreateData(TradeinValueModel model)
 {
     try
     {
         using (var context = new VincontrolEntities())
         {
             if (model.Trim != null)
             {
                 var tradein = new TrimTradeIn();
                 tradein.TrimId    = model.Trim.Value;
                 tradein.SampleVIN = model.SampleVin;
                 //decimal tradeinValue = 0;
                 //decimal.TryParse(TradeInValue.Text, out tradeinValue);
                 if (model.TradeinValue != null)
                 {
                     tradein.TradeInValue = model.TradeinValue.Value;
                 }
                 //long estimatedMileage = 0;
                 //long.TryParse(EstimatedMileage.Text, out estimatedMileage);
                 tradein.EstimatedZeroPointMileage = model.EstimatedMileage;
                 context.AddToTrimTradeIns(tradein);
                 context.SaveChanges();
                 MessageBox.Show("Tradein information has been successfully added.");
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("There is already this year make model trim in the database.");
     }
 }
예제 #3
0
        //private static void UpdatePriceChangeActivity()
        //{
        //    using (var dataContext = new VincontrolEntities())
        //    {
        //        foreach (var item in dataContext.InventoryDealerActivities.Where(i => i.DealerActivitySubTypeCodeId == 10))
        //        {
        //            if (string.IsNullOrEmpty(item.Detail)) continue;
        //            var resultString = item.Detail.Split(',');
        //            var inventoryId = resultString[0];

        //            //item.VIN = GetContent(vinString).Trim();
        //            //item.Stock = GetContent(stockString).Trim();
        //            var oldInventoryId = int.Parse(GetContent(inventoryId).Trim());
        //            item.OldPrice = decimal.Parse(GetContent(resultString[2].Split(';')[0]).Trim(), NumberStyles.Currency);
        //            if (resultString[2].Split(';').Length >= 2)
        //            {
        //                item.NewPrice = decimal.Parse(GetContent(resultString[2].Split(';')[1]).Trim(),
        //                                              NumberStyles.Currency);
        //            }
        //            var inventory = dataContext.Inventories.Include("Vehicle").FirstOrDefault(i => i.OldInventoryId == oldInventoryId);
        //            if (inventory != null)
        //            {
        //                item.InventoryId = inventory.InventoryId;
        //                item.VIN = inventory.Vehicle.Vin;
        //                item.Stock = inventory.Stock;
        //                item.Year = inventory.Vehicle.Year;
        //                item.Make = inventory.Vehicle.Make;
        //                item.Model = inventory.Vehicle.Model;
        //                item.Trim = inventory.Vehicle.Trim;

        //            }
        //        }

        //        dataContext.SaveChanges();
        //    }
        //}

        private static void UpdatePriceChangeActivity()
        {
            using (var dataContext = new VincontrolEntities())
            {
                foreach (var item in dataContext.InventoryDealerActivities.Where(i => i.DealerActivitySubTypeCodeId == 10))
                {
                    if (string.IsNullOrEmpty(item.Detail))
                    {
                        continue;
                    }
                    var resultString = item.Detail.Split(';');
                    item.NewPrice = decimal.Parse(GetContent(resultString[1]).Trim(),
                                                  NumberStyles.Currency);
                    var newResultString = resultString[0].Split('$');
                    item.OldPrice = decimal.Parse(newResultString[1],
                                                  NumberStyles.Currency);
                    var oldInventoryId = int.Parse(GetContent(newResultString[0].Split(',')[0]));

                    var inventory = dataContext.Inventories.Include("Vehicle").FirstOrDefault(i => i.OldInventoryId == oldInventoryId);
                    if (inventory != null)
                    {
                        item.InventoryId = inventory.InventoryId;
                        item.VIN         = inventory.Vehicle.Vin;
                        item.Stock       = inventory.Stock;
                        item.Year        = inventory.Vehicle.Year;
                        item.Make        = inventory.Vehicle.Make;
                        item.Model       = inventory.Vehicle.Model;
                        item.Trim        = inventory.Vehicle.Trim;
                    }
                }

                dataContext.SaveChanges();
            }
        }
예제 #4
0
        private void TrackActivity(string emails, string names, Inventory existingInventory, User user)
        {
            var emailList = emails.Split(',').ToList();
            var nameList  = names.Split(',').ToList();

            using (var context = new VincontrolEntities())
            {
                for (var i = 0; i < emailList.Count; i++)
                {
                    var activity = new FlyerShareDealerActivity
                    {
                        CustomerEmail = emailList[i],
                        CustomerName  = nameList[i],
                        DateStamp     = DateTime.Now,
                        UserStampId   = user.UserId,
                        DealerId      = existingInventory.Dealer.DealerId,
                        Year          = existingInventory.Vehicle.Year,
                        Make          = existingInventory.Vehicle.Make,
                        Model         = existingInventory.Vehicle.Model,
                        Trim          = existingInventory.Vehicle.Trim,
                        Stock         = existingInventory.Stock,
                        VIN           = existingInventory.Vehicle.Vin,
                        IsBrochure    = false
                    };
                    context.AddToFlyerShareDealerActivities(activity);
                }
                context.SaveChanges();
            }
        }
예제 #5
0
        private static void UpdateInventoryActivity()
        {
            using (var dataContext = new VincontrolEntities())
            {
                foreach (var item in dataContext.InventoryDealerActivities.Where(i => i.DealerActivitySubTypeCodeId == 13))
                {
                    if (string.IsNullOrEmpty(item.Detail))
                    {
                        continue;
                    }
                    var resultString = item.Detail.Split(';');
                    var appraisalId  = resultString[0];
                    var inventoryId  = resultString[1];
                    //var vinString = resultString[1];
                    //var stockString = resultString[2];
                    var yearString  = resultString[2];
                    var makeString  = resultString[3];
                    var modelString = resultString[4];
                    var trimString  = resultString[5];

                    //item.VIN = GetContent(vinString).Trim();
                    //item.Stock = GetContent(stockString).Trim();
                    var oldInventoryId = int.Parse(GetContent(inventoryId).Trim());

                    var inventory = dataContext.Inventories.Include("Vehicle").FirstOrDefault(i => i.OldInventoryId == oldInventoryId);
                    if (inventory != null)
                    {
                        item.InventoryId = inventory.InventoryId;
                        item.VIN         = inventory.Vehicle.Vin;
                        item.Stock       = inventory.Stock;
                    }

                    if (!string.IsNullOrEmpty(GetContent(appraisalId).Trim()))
                    {
                        var oldAppraisalId = int.Parse(GetContent(appraisalId));
                        var appraisal      = dataContext.Appraisals.FirstOrDefault(i => i.OldAppraisalId == oldAppraisalId);

                        if (appraisal != null)
                        {
                            item.AppraisalId = appraisal.AppraisalId;
                        }
                    }
                    item.Year  = int.Parse(GetContent(yearString).Trim());
                    item.Make  = GetContent(makeString).Trim();
                    item.Model = GetContent(modelString).Trim();
                    item.Trim  = GetContent(trimString).Trim();
                }
                dataContext.SaveChanges();
            }
        }
예제 #6
0
        private void CreateData(int trimId)
        {
            using (var context = new VincontrolEntities())
            {
                var tradein = new TrimTradeIn();

                //tradein.TrimId = trimId;
                //tradein.SampleVIN = SampleVin.Text;
                //decimal tradeinValue = 0;
                //decimal.TryParse(TradeInValue.Text, out tradeinValue);
                //tradein.TradeInValue = tradeinValue;
                //long estimatedMileage = 0;
                //long.TryParse(EstimatedMileage.Text, out estimatedMileage);
                //tradein.EstimatedZeroPointMileage = estimatedMileage;
                //context.AddToTrimTradeIns(tradein);
                context.SaveChanges();
            }
        }
예제 #7
0
        private static void UpdateAppraisalActivity()
        {
            using (var dataContext = new VincontrolEntities())
            {
                foreach (var item in dataContext.AppraisalDealerActivities)
                {
                    if (string.IsNullOrEmpty(item.Detail) || item.Detail.Contains("Stock Number"))
                    {
                        continue;
                    }
                    var resultString      = item.Detail.Split(';');
                    var appraisalIdString = resultString[0];
                    var vinString         = resultString[1];
                    //var stockString = resultString[2];
                    var yearString  = resultString[2];
                    var makeString  = resultString[3];
                    var modelString = resultString[4];
                    var trimString  = resultString[5];

                    item.VIN = GetContent(vinString).Trim();
                    //item.Stock = GetContent(stockString).Trim();
                    var oldAppraisalId = int.Parse(GetContent(appraisalIdString).Trim());
                    var appraisal      = dataContext.Appraisals.FirstOrDefault(i => i.OldAppraisalId == oldAppraisalId);
                    item.Stock = null;
                    if (appraisal != null)
                    {
                        item.AppraisalId = appraisal.AppraisalId;
                        item.Stock       = appraisal.Stock;
                    }
                    item.Year  = int.Parse(GetContent(yearString).Trim());
                    item.Make  = GetContent(makeString).Trim();
                    item.Model = GetContent(modelString).Trim();
                    item.Trim  = GetContent(trimString).Trim();
                }
                dataContext.SaveChanges();
            }
        }
예제 #8
0
        private void SaveImageUrl()
        {
            using (var dbContext = new VincontrolEntities())
            {
                var row =
                    dbContext.Inventories.FirstOrDefault(x => x.InventoryId == _vm.ListingId);
                if (row != null)
                {
                    if (String.IsNullOrEmpty(row.PhotoUrl))
                    {
                        row.PhotoUrl = GetFileUrLs();
                    }
                    else
                    {
                        string[] carImagesList = row.PhotoUrl.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        if (carImagesList.First().Contains(GetWebURL()))
                        {
                            if (carImagesList.First().Contains("DefaultStockImage"))
                            {
                                row.PhotoUrl = GetFileUrLs();
                            }
                            else
                            {
                                row.PhotoUrl = row.PhotoUrl + "," + GetFileUrLs();
                            }
                        }
                        else
                        {
                            row.PhotoUrl = GetFileUrLs();
                        }
                    }

                    if (String.IsNullOrEmpty(row.ThumbnailUrl))
                    {
                        row.ThumbnailUrl = GetThumbnailFileUrLs();
                    }
                    else
                    {
                        string[] carImagesList = row.ThumbnailUrl.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        if (carImagesList.First().Contains(GetWebURL()))
                        {
                            if (carImagesList.First().Contains("DefaultStockImage"))
                            {
                                row.ThumbnailUrl = GetThumbnailFileUrLs();
                            }
                            else
                            {
                                row.ThumbnailUrl = row.ThumbnailUrl + "," + GetThumbnailFileUrLs();
                            }
                        }
                        else
                        {
                            row.ThumbnailUrl = GetThumbnailFileUrLs();
                        }
                    }

                    row.LastUpdated = DateTime.Now;

                    dbContext.SaveChanges();
                }
            }
        }
예제 #9
0
        public static void Rename(string fromPath, string toPath, int dealerId, string alternativeSubFolder = "Corrected", bool makeOverlay = false)
        {
            Console.WriteLine("*** START ***");
            var context    = new VincontrolEntities();
            var rootFolder = new DirectoryInfo(fromPath);

            if (rootFolder.Exists)
            {
                var subFolders = Directory.GetDirectories(fromPath);
                foreach (var item in subFolders)
                {
                    var subFolder             = new DirectoryInfo(item + (String.IsNullOrEmpty(alternativeSubFolder) ? "" : "\\" + alternativeSubFolder));
                    var subFolderName         = Path.GetFileName(item);
                    var listOfNormalImages    = new List <string>();
                    var listOfThumbnailImages = new List <string>();
                    Console.WriteLine("*** {0} ***", subFolderName);
                    var inventory = context.Inventories.FirstOrDefault(i => i.Vehicle.Vin.Equals(subFolderName) && i.DealerId.Equals(dealerId));
                    if (inventory == null)
                    {
                        continue;
                    }

                    var newNormalFolder    = toPath + "\\" + subFolderName + "\\" + "NormalSizeImages";
                    var newThumbnailFolder = toPath + "\\" + subFolderName + "\\" + "ThumbnailSizeImages";
                    if (!Directory.Exists(newNormalFolder))
                    {
                        Directory.CreateDirectory(newNormalFolder);
                    }
                    if (!Directory.Exists(newThumbnailFolder))
                    {
                        Directory.CreateDirectory(newThumbnailFolder);
                    }

                    var count = 1;
                    foreach (FileInfo image in subFolder.GetFiles().OrderBy(f => f.CreationTime))
                    {
                        if (image != null && (image.Extension.Equals(".jpg") || image.Extension.Equals(".png")) && (String.IsNullOrEmpty(inventory.PhotoUrl) || inventory.PhotoUrl.ToLower().Contains(image.Name.ToLower())))
                        {
                            var newImageName = String.Format("{0} {1} {2} {3}.jpg", inventory.Vehicle.Year, inventory.Vehicle.Make, inventory.Vehicle.Model, string.IsNullOrEmpty(inventory.Vehicle.Trim) ? (count++).ToString() : inventory.Vehicle.Trim + " " + (count++).ToString());
                            newImageName = newImageName.Replace(" ", "-").Replace("/", "").Replace("\\", "");
                            //image.CopyTo(newNormalFolder + "\\" + newImageName, true);
                            //File.Copy(image.FullName, newNormalFolder + "\\" + newImageName, true);
                            if (!File.Exists(newNormalFolder + "\\" + newImageName))
                            {
                                image.CopyTo(newNormalFolder + "\\" + newImageName, true);
                            }

                            if (makeOverlay)
                            {
                                OverlayImage(newNormalFolder + "\\" + newImageName, newNormalFolder + "\\" + newImageName, dealerId);
                            }
                            Console.WriteLine(newNormalFolder + "\\" + newImageName);
                            var imgObj = Image.FromFile(/*image.FullName*/ newNormalFolder + "\\" + newImageName);
                            var tmp    = Resize(imgObj, 260, 210);
                            WriteFile(tmp, newThumbnailFolder + "\\", newImageName);
                            //if (makeOverlay) OverlayImage(newThumbnailFolder + "\\" + newImageName, newThumbnailFolder + "\\" + newImageName, dealerId);

                            listOfNormalImages.Add(String.Format("http://apps.vincontrol.com/DealerImages/{0}/{1}/{2}/{3}", dealerId, subFolderName, "NormalSizeImages", newImageName));
                            listOfThumbnailImages.Add(String.Format("http://apps.vincontrol.com/DealerImages/{0}/{1}/{2}/{3}", dealerId, subFolderName, "ThumbnailSizeImages", newImageName));
                        }
                    }

                    if (listOfNormalImages.Any())
                    {
                        {
                            inventory.PhotoUrl     = listOfNormalImages.Aggregate((x, y) => x + "," + y);
                            inventory.ThumbnailUrl = listOfThumbnailImages.Aggregate((x, y) => x + "," + y);
                        }
                    }
                }
                context.SaveChanges();
            }
            Console.WriteLine("*** END ***");
        }