private async Task <string> SaveAutoPartImageFromNotificationAndDeletePreviousImageIfItExists(
            UpdateAutoPartNotification notification,
            AutoPart entity)
        {
            if (!string.IsNullOrEmpty(notification.ImageFileName) && !notification.ImageFileBuffer.IsEmpty)
            {
                if (!string.IsNullOrEmpty(entity.Image))
                {
                    var deleteFileNotification = new DeleteFileNotification
                    {
                        FileName = entity.Image
                    };

                    await mediator.Publish(deleteFileNotification)
                    .ConfigureAwait(false);
                }

                var saveFileRequest = new SaveFileRequest
                {
                    FileName = notification.ImageFileName,
                    Buffer   = notification.ImageFileBuffer
                };

                return(await mediator.Send(saveFileRequest)
                       .ConfigureAwait(false));
            }

            return(entity.Image);
        }
        public void InsertDataIntoDB(IEnumerable<string> content, IList<string> format)
        {
            int indexForName = format.IndexOf("Name");
            int indexForDescription = format.IndexOf("Description");
            int indexForPrice = format.IndexOf("Price");
            int indexForCompatibility = format.IndexOf("Compatibility");
            int indexForManufacturer = format.IndexOf("Manufacturer");
            int indexForType = format.IndexOf("Type");
            int iterations = 1;

            foreach (var singleRow in content)
            {
                var rowEntities = singleRow.Split(new[] { Constants.DividerForExcelRead }, StringSplitOptions.None);
                var autoPartObject = new AutoPart();
                autoPartObject.Name = rowEntities[indexForName];
                autoPartObject.Description = rowEntities[indexForDescription];
                autoPartObject.Price = decimal.Parse(rowEntities[indexForPrice]);
                autoPartObject.Compatibility = this.db.Compatibilities.Find(int.Parse(rowEntities[indexForCompatibility]));
                autoPartObject.Manufacturer = this.db.Manufacturers.Find(int.Parse(rowEntities[indexForManufacturer]));
                autoPartObject.Type = this.db.PartTypes.Find(int.Parse(rowEntities[indexForType]));
                autoPartObject.BuiltOn = DateTime.Now;

                if (iterations % 100 == 0)
                {
                    this.db.SaveChanges();
                    this.db.Dispose();
                    this.db = new AutopartsDbContext();
                }

                this.db.AutoParts.Add(autoPartObject);
                iterations++;
            }

            this.db.SaveChanges();
        }
Exemplo n.º 3
0
        public ActionResult Image([Bind(Include = "Id,PartNo")] AutoPart autopart, HttpPostedFileBase fileAutoPart)
        {
            if (fileAutoPart != null)
            {
                string fileName          = autopart.Id.ToString() + "-" + autopart.PartNo;
                string file_ext          = Path.GetExtension(fileAutoPart.FileName);
                string fileAutoPartImage = fileName + file_ext;

                if (fileUtil.ValidImageExtension(file_ext))
                {
                    string path = Server.MapPath("~/AutoPartImages/" + fileAutoPartImage);
                    fileAutoPart.SaveAs(path);

                    string US_ConnStr = ConfigurationManager.ConnectionStrings["PHIYESA_ADO"].ConnectionString;
                    using (SqlConnection sqlCon = new SqlConnection(US_ConnStr))
                    {
                        SqlCommand sqlCmd = new SqlCommand();
                        sqlCmd.CommandText = "Update AutoPart Set PartImage = @autopart_imagefilename Where Id = @Id";
                        sqlCmd.Parameters.AddWithValue("@autopart_imagefilename", fileAutoPartImage);
                        sqlCmd.Parameters.AddWithValue("@Id", autopart.Id);
                        sqlCmd.Connection = sqlCon;
                        sqlCon.Open();
                        int rowaffected = sqlCmd.ExecuteNonQuery();
                        sqlCon.Close();
                    }
                }
                else
                {
                    ViewBag.FileErrorMessage = "File Upload ERROR: Only JPG files are allowed to upload ... ";
                    return(View(autopart));
                }
            } //--

            return(RedirectToAction("Details/" + autopart.Id.ToString()));
        } //--
Exemplo n.º 4
0
        public ActionResult CreatePartII([Bind(Include = "Id,PartNo,Make,Model,PartSubCategory")] AutoPart autoPart)
        {
            int partId = autoPart.Id;

            int?partSubCategory = autoPart.PartSubCategory;

            string US_ConnStr = ConfigurationManager.ConnectionStrings["PHIYESA_ADO"].ConnectionString;;

            using (SqlConnection sqlCon = new SqlConnection(US_ConnStr))
            {
                SqlCommand sqlCmd = new SqlCommand();
                sqlCmd.CommandText = "Update AutoPart Set PartSubCategory = @sub_category, Model = @car_model  Where Id = @part_id";

                sqlCmd.Parameters.AddWithValue("@sub_category", autoPart.PartSubCategory);
                sqlCmd.Parameters.AddWithValue("@car_model", autoPart.Model);
                sqlCmd.Parameters.AddWithValue("@part_id", autoPart.Id);

                sqlCmd.Connection = sqlCon;
                sqlCon.Open();
                int rowaffected = sqlCmd.ExecuteNonQuery();
                sqlCon.Close();
            }

            return(RedirectToAction("Details/" + autoPart.Id.ToString()));

            //return View();
        } //--
Exemplo n.º 5
0
        public void AddContent(AutoPart entry)
        {
            MySqlCommand cmd;

            connection.Open();
            try
            {
                cmd             = connection.CreateCommand();
                cmd.CommandText = "INSERT INTO Autoparts (Name,Description,Price) VALUES (@Name,@Description,Price)";
                cmd.Parameters.AddWithValue("@Name", entry.Name);
                cmd.Parameters.AddWithValue("@Description", entry.Description);
                cmd.Parameters.AddWithValue("@Price", entry.Price);
                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
        }
Exemplo n.º 6
0
        public HttpResponseMessage AddAutoPart(
            [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string sessionKey, AutoPartAddModel model)
        {
            var responseMsg = this.ExceptionHandler(
                () =>
            {
                var context = new AutoMorgueContext();


                var users = context.Users;
                var user  = users.FirstOrDefault(
                    usr => usr.SessionKey == sessionKey);

                if (user.Role.Name != "admin")
                {
                    throw new InvalidOperationException("You don't have permission to add auto parts.");
                }

                var morgue = context.Morgues.Where(m => m.Name == model.Morgue).FirstOrDefault();

                if (morgue == null)
                {
                    throw new InvalidOperationException();
                }

                var cat = context.Categories.FirstOrDefault(c => c.Name == model.Name);

                if (cat == null)
                {
                    cat = new Category
                    {
                        Name = model.Category
                    };
                }

                var newAutoPart = new AutoPart
                {
                    Name     = model.Name,
                    Price    = model.Price,
                    Quantity = model.Quantity,
                    Morgue   = morgue,
                    Category = cat
                };

                context.AutoParts.Add(newAutoPart);
                context.SaveChanges();

                var createdModel = new CreatedAutoPartModel
                {
                    Name = newAutoPart.Name
                };

                var response = this.Request.CreateResponse(HttpStatusCode.Created, createdModel);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = newAutoPart.Id }));

                return(response);
            });

            return(responseMsg);
        }
        public async Task <IActionResult> PutAutoPart(int id, AutoPart autoPart)
        {
            if (id != autoPart.Id)
            {
                return(BadRequest());
            }

            this.db.Entry(autoPart).State = EntityState.Modified;

            try
            {
                await this.db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AutoPartExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public ActionResult Create(AutoPart ap, HttpPostedFileBase imageUpload = null)
        {
            if (ModelState.IsValid)
            {
                if (imageUpload != null)
                {
                    var count = imageUpload.ContentLength;
                    ap.Image = new byte[count];
                    imageUpload.InputStream.Read(ap.Image, 0, (int)count);
                    ap.MimeType = imageUpload.ContentType;
                }
                try
                {
                    repository.CreateAutoPart(ap);

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    //return View(ap);
                    return(View());
                }
            }
            else
            {
                return(View(ap));
            }
        }
Exemplo n.º 9
0
        public void InsertDataIntoDB(IEnumerable <string> content, IList <string> format)
        {
            int indexForName          = format.IndexOf("Name");
            int indexForDescription   = format.IndexOf("Description");
            int indexForPrice         = format.IndexOf("Price");
            int indexForCompatibility = format.IndexOf("Compatibility");
            int indexForManufacturer  = format.IndexOf("Manufacturer");
            int indexForType          = format.IndexOf("Type");
            int iterations            = 1;

            foreach (var singleRow in content)
            {
                var rowEntities    = singleRow.Split(new[] { Constants.DividerForExcelRead }, StringSplitOptions.None);
                var autoPartObject = new AutoPart();
                autoPartObject.Name          = rowEntities[indexForName];
                autoPartObject.Description   = rowEntities[indexForDescription];
                autoPartObject.Price         = decimal.Parse(rowEntities[indexForPrice]);
                autoPartObject.Compatibility = this.db.Compatibilities.Find(int.Parse(rowEntities[indexForCompatibility]));
                autoPartObject.Manufacturer  = this.db.Manufacturers.Find(int.Parse(rowEntities[indexForManufacturer]));
                autoPartObject.Type          = this.db.PartTypes.Find(int.Parse(rowEntities[indexForType]));
                autoPartObject.BuiltOn       = DateTime.Now;

                if (iterations % 100 == 0)
                {
                    this.db.SaveChanges();
                    this.db.Dispose();
                    this.db = new AutopartsDbContext();
                }

                this.db.AutoParts.Add(autoPartObject);
                iterations++;
            }

            this.db.SaveChanges();
        }
Exemplo n.º 10
0
        public ActionResult CreatePartII(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            AutoPart autoPart = db.AutoParts.Find(id);

            if (autoPart == null)
            {
                return(HttpNotFound());
            }

            List <PartSubCategory> lstPartSubCategories    = db.PartSubCategories.Where(c => c.PartCategory == autoPart.PartCategory).ToList();
            SelectList             listOfPartSubCategories = new SelectList(lstPartSubCategories, "Id", "PartSubCategoryDesc");

            ViewBag.ListOfPartSubCategories = listOfPartSubCategories;

            List <AutoModel> lstCarModels    = db.AutoModels.Where(m => m.CarMake == autoPart.Make).ToList();
            SelectList       listOfCarModels = new SelectList(lstCarModels, "Id", "CarModelDesc");

            ViewBag.ListOfCarModels = listOfCarModels;

            return(View(autoPart));
        } //--
Exemplo n.º 11
0
        public ActionResult DeleteConfirmed(int id)
        {
            AutoPart autoPart = db.AutoParts.Find(id);

            db.AutoParts.Remove(autoPart);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 12
0
        public ActionResult Create([Bind(Include = "Id,PartNo,PartCategory,Year,Make,Model,PartDescription,Brand,MadeIn,EngineType,PartSubCategory,PartImage")] AutoPart autoPart)
        {
            if (ModelState.IsValid)
            {
                db.AutoParts.Add(autoPart);
                db.SaveChanges();

                return(RedirectToAction("CreatePartII/" + autoPart.Id.ToString()));
            }

            return(View(autoPart));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Удалить из корзины
        /// </summary>
        /// <param name="autoPart">Объект для удаления</param>
        public void RemoveItem(AutoPart autoPart)
        {
            var item = items.Find(i => i.autoPart.AutoPartId == autoPart.AutoPartId);

            if (item.quantity == 1)
            {
                items.Remove(item);
            }
            else
            {
                item.quantity -= 1;
            }
        }
        private async Task DeleteAutoPartImageIfItExists(AutoPart entity)
        {
            if (!string.IsNullOrEmpty(entity.Image))
            {
                var deleteFileNotification = new DeleteFileNotification
                {
                    FileName = entity.Image
                };

                await mediator.Publish(deleteFileNotification)
                .ConfigureAwait(false);
            }
        }
Exemplo n.º 15
0
        //public FileContentResult GetImage(int autoPartId)
        //{
        //    AutoPart ap = repository.GetAutoPart(autoPartId);

        //    if (ap != null && ap.Image != null)
        //        return File(ap.Image, ap.MimeType);
        //    else
        //    {
        //        return File(imageToView, type.ToString()); ;
        //    }
        //}

        public async Task <FileContentResult> GetImage(int autoPartId)
        {
            AutoPart ap = await repository.GetAutoPartAsync(autoPartId);

            if (ap != null && ap.Image != null)
            {
                return(File(ap.Image, ap.MimeType));
            }
            else
            {
                return(File(imageToView, type.ToString()));;
            }
        }
Exemplo n.º 16
0
        } //--

        // GET: AutoParts/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AutoPart autoPart = db.AutoParts.Find(id);

            if (autoPart == null)
            {
                return(HttpNotFound());
            }
            return(View(autoPart));
        }
Exemplo n.º 17
0
        /// <summary>
        /// Добавить в корзину
        /// </summary>
        /// <param name="autoPart">объект для добавления</param>
        public void AddItem(AutoPart autoPart)
        {
            var item = items.Find(i => i.autoPart.AutoPartId == autoPart.AutoPartId);

            if (item == null)
            {
                items.Add(new CartItem {
                    autoPart = autoPart, quantity = 1
                });
            }
            else
            {
                item.quantity += 1;
            }
        }
Exemplo n.º 18
0
        private void AutoPartTextbox_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(AutoPartTextbox.Text))
            {
                AutoPart part = this.autoPartController.FetchAutoPartByName(AutoPartTextbox.Text.Trim());

                if (part != null)
                {
                    partId = part.Id;
                }
                else
                {
                    partId = 0;
                }
            }
        }
Exemplo n.º 19
0
        public ActionResult Edit([Bind(Include = "Id,PartNo,PartCategory,Year,Make,Model,PartDescription,Brand,MadeIn,EngineType,PartSubCategory,PartImage")] AutoPart autoPart)
        {
            if (ModelState.IsValid)
            {
                db.Entry(autoPart).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("CreatePartII", new { id = autoPart.Id }));
            }

            SelectListCommon selCommonObj = new SelectListCommon();

            ViewBag.ListOfPartCategories = selCommonObj.ListOfPartCategories();
            ViewBag.ListOfAutoYears      = selCommonObj.listOfAutoYears();
            ViewBag.ListOfCarMakes       = selCommonObj.listOfCarMakes();
            ViewBag.ListOfAutoBrands     = selCommonObj.listOfAutoBrands();
            ViewBag.ListOfCountryMadeIn  = selCommonObj.listOfCountryMadeIn();

            return(View(autoPart));
        } //--
        public async Task <ActionResult <AutoPart> > PostAutoPart(int id, AutoPart autoPartVM)
        {
            if (autoPartVM == null)
            {
                return(NotFound());
            }

            var autoParts = await this.db.ModelCars.Include(autoPart => autoPart.AutoParts)
                            .SingleOrDefaultAsync(modelCar => modelCar.Id == id);

            autoParts.AutoParts.Add(new AutoPart()
            {
                Name     = autoPartVM.Name,
                ModelCar = autoParts
            });

            this.db.Update(autoParts);
            await this.db.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 21
0
        public void AddAutoPart(AutoPart autoPart, int quantity)
        {
            var existingCartItem = cartItems.FirstOrDefault(cartItem => cartItem.AutoPart.Id == autoPart.Id);

            if (existingCartItem != null)
            {
                existingCartItem.Quantity = quantity;
            }
            else
            {
                var newCartItem = new CartItemModel
                {
                    AutoPart = autoPart,
                    Quantity = quantity
                };

                cartItems.Add(newCartItem);
            }

            WriteCartItemsToLocalStorage();
        }
Exemplo n.º 22
0
        // GET: AutoParts/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            AutoPart autoPart = db.AutoParts.Find(id);

            if (autoPart == null)
            {
                return(HttpNotFound());
            }

            SelectListCommon selCommonObj = new SelectListCommon();

            ViewBag.ListOfPartCategories = selCommonObj.ListOfPartCategories();
            ViewBag.ListOfAutoYears      = selCommonObj.listOfAutoYears();
            ViewBag.ListOfCarMakes       = selCommonObj.listOfCarMakes();
            ViewBag.ListOfAutoBrands     = selCommonObj.listOfAutoBrands();
            ViewBag.ListOfCountryMadeIn  = selCommonObj.listOfCountryMadeIn();

            return(View(autoPart));
        }
        public void UpdateAutoPart(AutoPartColumnModel model)
        {
            try
            {
                using (this.unitOfWork)
                {
                    var item = FetchAutoPartDetailById(model.Id);
                    if (item != null)
                    {
                        //Auto Part
                        if (item.AutoPartId != null & item.AutoPartId.Value != model.PartId)
                        {
                            AutoPart part = FetchAutoPartById(model.PartId);
                            if (part != null)
                            {
                                item.AutoPartId = model.PartId;
                            }
                            else
                            {
                                AutoPart newPart = new AutoPart();
                                newPart.PartName  = model.PartName;
                                newPart.IsDeleted = false;

                                item.AutoPart = newPart;
                            }
                        }

                        if (item.AutoPartAltPartNumber.Any())
                        {
                            item.AutoPartAltPartNumber.Clear();
                        }

                        if (model.AutoPartDetail.AltPartNumbers.Any())
                        {
                            foreach (var alt in model.AutoPartDetail.AltPartNumbers)
                            {
                                if (!item.AutoPartAltPartNumber.Any(a => a.AltPartNumber == alt))
                                {
                                    item.AutoPartAltPartNumber.Add(
                                        new AutoPartAltPartNumber()
                                    {
                                        AltPartNumber = alt
                                    });
                                }
                            }
                        }

                        //Auto Part Detail
                        if (model.AutoPartDetail != null)
                        {
                            item.Make       = model.AutoPartDetail.Make;
                            item.Model      = model.AutoPartDetail.Model;
                            item.BrandId    = model.AutoPartDetail.BrandId;
                            item.PartNumber = model.AutoPartDetail.PartNumber;
                            //item.AltPartNumber = model.AutoPartDetail.AltPartNumber;
                            item.SellingPrice1 = model.AutoPartDetail.SellingPrice;
                            item.SellingPrice2 = model.AutoPartDetail.SellingPrice2;
                            item.Unit          = model.AutoPartDetail.Unit;
                            item.ReorderLimit  = model.AutoPartDetail.ReorderLimit;
                            item.BuyingPrice   = model.AutoPartDetail.PurchasePrice;
                            item.Size          = model.AutoPartDetail.Size;
                            item.Description   = model.AutoPartDetail.Description;
                            item.Quantity      = model.AutoPartDetail.Quantity;

                            if (!string.IsNullOrWhiteSpace(item.Picture))
                            {
                                RemovePictureFile(item.Picture);
                            }

                            if (!string.IsNullOrWhiteSpace(model.AutoPartDetail.Picture))
                            {
                                if (string.Compare(item.Picture, model.AutoPartDetail.Picture, true) != 0)
                                {
                                    item.Picture = Path.GetFileName(model.AutoPartDetail.Picture);
                                    SavePictureFile(model.AutoPartDetail.Picture);
                                }
                            }
                            else
                            {
                                item.Picture = string.Empty;
                            }
                        }
                    }

                    string action = string.Format("Updated Auto Part - {0}", model.PartName);
                    this.actionLogController.AddToLog(action, UserInfo.UserId);

                    this.unitOfWork.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void InsertAutoPart(AutoPartColumnModel model)
        {
            try
            {
                using (this.unitOfWork)
                {
                    AutoPart item = FetchAutoPartById(model.PartId);
                    if (item != null)
                    {
                        item.PartName = model.PartName;
                    }
                    else
                    {
                        item = new AutoPart()
                        {
                            PartName  = model.PartName,
                            IsDeleted = false
                        };

                        db.AddToAutoPart(item);
                    }

                    //Add details
                    if (model.AutoPartDetail != null)
                    {
                        AutoPartDetailColumnModel detail = model.AutoPartDetail;
                        AutoPartDetail            d      = new AutoPartDetail()
                        {
                            Make          = detail.Make,
                            Model         = detail.Model,
                            BrandId       = detail.BrandId,
                            IsDeleted     = false,
                            PartNumber    = detail.PartNumber,
                            Quantity      = detail.Quantity,
                            SellingPrice1 = detail.SellingPrice,
                            SellingPrice2 = detail.SellingPrice2,
                            Unit          = detail.Unit,
                            ReorderLimit  = detail.ReorderLimit,
                            BuyingPrice   = detail.PurchasePrice,
                            Size          = detail.Size,
                            Picture       = !string.IsNullOrWhiteSpace(detail.Picture) ? Path.GetFileName(detail.Picture) : string.Empty,
                            Description   = detail.Description
                        };

                        if (model.AutoPartDetail.AltPartNumbers.Count > 0)
                        {
                            foreach (string n in model.AutoPartDetail.AltPartNumbers)
                            {
                                AutoPartAltPartNumber altNumber = new AutoPartAltPartNumber()
                                {
                                    AltPartNumber = n
                                };
                                d.AutoPartAltPartNumber.Add(altNumber);
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(model.AutoPartDetail.Picture))
                        {
                            SavePictureFile(model.AutoPartDetail.Picture);
                        }

                        item.AutoPartDetail.Add(d);
                    }

                    string action = string.Format("Added new Auto Part - {0} {1}", model.PartName, model.AutoPartDetail.PartNumber);
                    this.actionLogController.AddToLog(action, UserInfo.UserId);

                    this.unitOfWork.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected override void Seed(ModelContext context)
        {
            var part1 = new AutoPart {
                Name = "Подшипник"
            };

            context.AutoParts.Add(part1);

            var part2 = new AutoPart {
                Name = "Шаровая опора"
            };

            context.AutoParts.Add(part2);

            var part3 = new AutoPart {
                Name = "Ремень ГРМ"
            };

            context.AutoParts.Add(part3);

            var part4 = new AutoPart {
                Name = "Ручейковый ремень"
            };

            context.AutoParts.Add(part4);

            var part5 = new AutoPart {
                Name = "Свечи"
            };

            context.AutoParts.Add(part5);

            var part6 = new AutoPart {
                Name = "Фильтр"
            };

            context.AutoParts.Add(part6);

            var part7 = new AutoPart {
                Name = "Амортизатор"
            };

            context.AutoParts.Add(part7);

            var part8 = new AutoPart {
                Name = "Рычаг"
            };

            context.AutoParts.Add(part8);

            var part9 = new AutoPart {
                Name = "Ролик"
            };

            context.AutoParts.Add(part9);

            var part10 = new AutoPart {
                Name = "Комплект ГРМ"
            };

            context.AutoParts.Add(part10);

            var part11 = new AutoPart {
                Name = "Фара"
            };

            context.AutoParts.Add(part11);

            var part12 = new AutoPart {
                Name = "Сцепление"
            };

            context.AutoParts.Add(part12);

            var part13 = new AutoPart {
                Name = "Поршень"
            };

            context.AutoParts.Add(part13);

            var part14 = new AutoPart {
                Name = "Вкладыши"
            };

            context.AutoParts.Add(part14);

            var part15 = new AutoPart {
                Name = "Поршневые кольца"
            };

            context.AutoParts.Add(part15);

            var part16 = new AutoPart {
                Name = "Помпа"
            };

            context.AutoParts.Add(part16);

            var part17 = new AutoPart {
                Name = "Радиатор"
            };

            context.AutoParts.Add(part17);

            var part18 = new AutoPart {
                Name = "Диск тормозной"
            };

            context.AutoParts.Add(part18);

            var part19 = new AutoPart {
                Name = "Колодки тормозные"
            };

            context.AutoParts.Add(part19);

            var part20 = new AutoPart {
                Name = "Тормозной шланг"
            };

            context.AutoParts.Add(part20);

            var brand1 = new Brand
            {
                Name      = "Lemforder",
                Logo      = ".\\Content\\Logo\\Lemforder.jpg".GetBytes(),
                Info      = "О компании LEMFÖRDER стоит говорить как о марке, под знаком которой выпускаются надежные и качественные автозапчасти. Подвеска и рулевое управление-специализация компании. Потребителям предлагается 13 000 наименований деталей для легкового и грузового транспорта, каждая из которых отвечает высоким требованиям надежности и комфорта. Сегодня данная компания может похвастаться тем, что она была выбрана в качестве официального поставщика производимой продукции для всех автомобильных концернов Европы. Чтобы осуществлять оперативное управление производством и поставками, производственные мощности LEMFORDER находятся чуть ли не в каждой стране.",
                ImageType = "jpg"
            };

            context.Brands.Add(brand1);

            var brand2 = new Brand
            {
                Name      = "SKF",
                Logo      = ".\\Content\\Logo\\SKF.jpg".GetBytes(),
                Info      = "AB SKF — шведская интернациональная машиностроительная компания, крупнейший в мире производитель подшипников, систем смазки и мехатроники. Штаб-квартира компании расположена в Гётеборге.",
                ImageType = "jpg"
            };

            context.Brands.Add(brand2);

            var brand3 = new Brand
            {
                Name      = "Patron",
                Logo      = ".\\Content\\Logo\\Patron.jpg".GetBytes(),
                Info      = "PATRON является собственной торговой маркой компании Шате - М  Плюс,  созданной  для обеспечения покупателей высококачественными автозапчастями для ремонта и технического обслуживания автомобилей. Торговая марка PATRON зарегистрирована в 2004 году и имеет международную регистрацию.",
                ImageType = "jpg"
            };

            context.Brands.Add(brand3);

            var brand4 = new Brand
            {
                Name      = "Kolbenschmidt",
                Logo      = ".\\Content\\Logo\\Kolbenschmidt.jpg".GetBytes(),
                Info      = "Уже более 80 лет компания KOLBENSCHMIDT занимается разработкой и производством различных типов автомобильных двигателей и запчастей для них. Ассортимент выпускаемой продукции огромен, как и перечень крупнейших автомобильных заводов, которые используют ее на своих конвейерах. Такая востребованность обусловлена тем, что автозапчасти KOLBENSCHMIDT отличаются точностью форм и долговечностью, их использование гарантирует экономичный расход топлива, надежность и безопасность эксплуатации автомобиля.",
                ImageType = "jpg"
            };

            context.Brands.Add(brand4);

            var brand5 = new Brand
            {
                Name      = "NGK",
                Logo      = ".\\Content\\Logo\\NGK.jpg".GetBytes(),
                Info      = " Компания NGK  — ведущий мировой производитель свечей зажигания. Компания имеет богатый инженерно-технический опыт по разработке свечей зажигания, свечей накаливания и кислородных датчиков для двигателей многих европейских автомобилей. Более 87% всех мировых автоконцернов, выпускающих легковые автомобили, выбирают свечи зажигания NGK для конвейерной комплектации.",
                ImageType = "jpg"
            };

            context.Brands.Add(brand5);

            var brand6 = new Brand
            {
                Name      = "KNECHT",
                Logo      = ".\\Content\\Logo\\KNECHT.jpg".GetBytes(),
                Info      = "Немецкая компания KNECHT известна на весь мир автомобильными фильтрами. Нельзя сказать, что ее путь на вершину был долгим и тернистым, потому что место на рынке было занято практически сразу. Адольф Кнехт, инженер из Германии, в 1899 году решил организовать производство фильтров, которые поначалу были производственными. Но заметив, с какой скоростью развивается автомобилестроение, ученый быстро переквалифицировался и не прогадал. Уже в 1929 году предприятие выпускало топливные, масляные и воздушные фильтры, а сама компания стала называться KNECHT FILTERWERKE. Именно ее инженеры в 1955 году на весь мир озвучили свое предложение использовать бумагу как фильтрующий элемент в автофильтрах",
                ImageType = "jpg"
            };

            context.Brands.Add(brand6);

            var brand7 = new Brand
            {
                Name      = "LuK",
                Logo      = ".\\Content\\Logo\\LUK.jpg".GetBytes(),
                Info      = "Продукция компании LuK настолько популярна, что сцепление под этой маркой используется в каждом втором немецком автомобиле и в каждом четвертом в мире. В каталоге компании более 1000 наименований, как говорится, на все случаи жизни.",
                ImageType = "jpg"
            };

            context.Brands.Add(brand7);

            var brand8 = new Brand
            {
                Name      = "JP Group",
                Logo      = ".\\Content\\Logo\\JP Group.jpg".GetBytes(),
                Info      = "JP Group – известная компания упаковщик автозапчастей. Продукция для вторичного рынка экспортируется в 70 стран мира. Годовой же оборот компании перешагнул отметку в 67 миллионов евро.",
                ImageType = "jpg"
            };

            context.Brands.Add(brand8);

            var brand9 = new Brand
            {
                Name      = "SNR",
                Logo      = ".\\Content\\Logo\\SNR.jpg".GetBytes(),
                Info      = "SNR является пионером в области высоких технологий с начала прошлого столетия и до нынешних времен. Из небольшой  скромной компании начала 20 века SNR превратилась в международный концерн, интересы которого представлены в более чем 120 странах мира. И везде, где бы ни были отделения, компания оказывает активную помощь в  конструировании, развитии новых технологий и промышленности.",
                ImageType = "jpg"
            };

            context.Brands.Add(brand9);

            var brand10 = new Brand
            {
                Name      = "TRW",
                Logo      = ".\\Content\\Logo\\TRW.jpg".GetBytes(),
                Info      = "TRW Automotive — один из ведущих мировых производителей тормозных систем и рулевого управления для легковых и грузовых автомобилей. Также TRW Automotive поставляет системы активной и пассивной безопасности для всех ведущих автомобилестоительных концернов. На сборочные конвейеры поставляются системы ABS, ESP, TC, системы рулевого управления и подвески, системы подушек безопасности и ремней безопасности и многое другое.",
                ImageType = "jpg"
            };

            context.Brands.Add(brand10);

            var country1 = new Country {
                Name = "Австрия"
            };
            var country2 = new Country {
                Name = "Франция"
            };
            var country3 = new Country {
                Name = "Германия"
            };
            var country4 = new Country {
                Name = "Китай"
            };
            var country5 = new Country {
                Name = "Швеция"
            };
            var country6 = new Country {
                Name = "Дания"
            };
            var country7 = new Country {
                Name = "Япония"
            };
            var country8 = new Country {
                Name = "Турция"
            };

            context.Countries.AddRange(new List <Country> {
                country1, country2, country3, country4, country5, country6, country7, country8
            });

            var description1 = new Feedback {
                Description = "Хорошая фирма, долго ходит, нариканий нет! Рекомендую!"
            };
            var description2 = new Feedback {
                Description = "Очень часто брак... Не рекомендую!"
            };
            var description3 = new Feedback {
                Description = "Китай одним словом!"
            };
            var description4 = new Feedback {
                Description = "Лучшие тормоза и колодки!"
            };
            var description5 = new Feedback {
                Description = "Ремень ГРМ порвался, сэкономил и попал на деньги..."
            };
            var description6 = new Feedback {
                Description = "Ни раазу не пожалел о выборе данных фильтров."
            };
            var description7 = new Feedback {
                Description = "Попадается брак."
            };
            var description8 = new Feedback {
                Description = "Не рекомендую!"
            };
            var description9 = new Feedback {
                Description = "Хорошие только колодки, диски плохие."
            };
            var description10 = new Feedback {
                Description = "Можно брать."
            };

            context.Feedbacks.AddRange(new List <Feedback> {
                description1, description2, description3, description4, description5, description6, description7, description8, description9, description10
            });

            var status1 = new Status {
                Name = "Упаковщик"
            };
            var status2 = new Status {
                Name = "Производитель"
            };

            context.Statuses.AddRange(new List <Status> {
                status1, status2
            });

            var model1 = new AutoModel {
                Name = "Audi"
            };
            var model2 = new AutoModel {
                Name = "VW"
            };
            var model3 = new AutoModel {
                Name = "Opel"
            };
            var model4 = new AutoModel {
                Name = "BMW"
            };
            var model5 = new AutoModel {
                Name = "Toyota"
            };
            var model6 = new AutoModel {
                Name = "Nissan"
            };
            var model7 = new AutoModel {
                Name = "Fiat"
            };
            var model8 = new AutoModel {
                Name = "Mazda"
            };
            var model9 = new AutoModel {
                Name = "Mersedes"
            };
            var model10 = new AutoModel {
                Name = "Volvo"
            };

            context.Models.AddRange(new List <AutoModel> {
                model1, model2, model3, model4, model5, model6, model7, model8, model9, model10
            });

            brand1.AutoParts = new List <AutoPart> {
                part2, part8
            };
            brand2.AutoParts = new List <AutoPart> {
                part1, part3, part4, part9, part10, part16
            };
            brand3.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };
            brand4.AutoParts = new List <AutoPart> {
                part13, part14, part15, part16
            };
            brand5.AutoParts = new List <AutoPart> {
                part5, part11
            };
            brand6.AutoParts = new List <AutoPart> {
                part6
            };
            brand7.AutoParts = new List <AutoPart> {
                part1, part7, part9, part12
            };
            brand8.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };
            brand9.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part9, part10, part16
            };
            brand10.AutoParts = new List <AutoPart> {
                part2, part8, part18, part19, part20
            };

            status1.Brands = new List <Brand> {
                brand3, brand8
            };
            status2.Brands = new List <Brand> {
                brand1, brand2, brand4, brand5, brand6, brand7, brand9, brand10
            };

            brand1.Feedbacks = new List <Feedback> {
                description1
            };
            brand2.Feedbacks = new List <Feedback> {
                description10
            };
            brand3.Feedbacks = new List <Feedback> {
                description2, description3, description5
            };
            //brand4.Feedbacks = new List<Feedback> {  };
            //brand4.Feedbacks = new List<Feedback> {  };
            //brand5.Feedbacks = new List<Feedback> {  };
            brand6.Feedbacks = new List <Feedback> {
                description6
            };
            //brand7.Feedbacks = new List<Feedback> { };
            brand8.Feedbacks = new List <Feedback> {
                description8
            };
            brand9.Feedbacks = new List <Feedback> {
                description7
            };
            brand10.Feedbacks = new List <Feedback> {
                description4, description9
            };

            country1.Brands.Add(brand6);
            country2.Brands.Add(brand9);
            country3.Brands = new List <Brand> {
                brand1, brand4, brand7, brand10
            };
            country4.Brands = new List <Brand> {
                brand1, brand3, brand6, brand8, brand9
            };
            country5.Brands.Add(brand2);
            country6.Brands.Add(brand8);
            country7.Brands.Add(brand5);
            country8.Brands = new List <Brand> {
                brand3, brand8
            };

            model1.Brands = new List <Brand> {
                brand1, brand2, brand3, brand4, brand5, brand6, brand7, brand8, brand9, brand10
            };
            model2.Brands = new List <Brand> {
                brand1, brand2, brand3, brand4, brand5, brand6, brand7, brand8, brand9, brand10
            };
            model3.Brands = new List <Brand> {
                brand1, brand2, brand3, brand4, brand5, brand6, brand7, brand8, brand9, brand10
            };
            model4.Brands = new List <Brand> {
                brand1, brand2, brand3, brand4, brand5, brand6, brand7, brand8, brand9, brand10
            };
            model5.Brands = new List <Brand> {
                brand1, brand2, brand3, brand4, brand5, brand6, brand7, brand8, brand9, brand10
            };
            model6.Brands = new List <Brand> {
                brand1, brand2, brand3, brand4, brand5, brand6, brand7, brand8, brand9, brand10
            };
            model7.Brands = new List <Brand> {
                brand1, brand2, brand3, brand4, brand5, brand6, brand7, brand8, brand9, brand10
            };
            model8.Brands = new List <Brand> {
                brand1, brand2, brand3, brand4, brand5, brand6, brand7, brand8, brand9, brand10
            };
            model9.Brands = new List <Brand> {
                brand1, brand2, brand3, brand4, brand5, brand6, brand7, brand8, brand9, brand10
            };
            model10.Brands = new List <Brand> {
                brand1, brand2, brand3, brand4, brand5, brand6, brand7, brand8, brand9, brand10
            };

            model1.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };
            model2.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };
            model3.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };
            model4.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };
            model5.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };
            model6.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };
            model7.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };
            model8.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };
            model9.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };
            model10.AutoParts = new List <AutoPart> {
                part1, part2, part3, part4, part5, part6, part7, part8, part9, part10, part11, part12, part13, part14, part15, part16, part17, part18, part19, part20
            };

            context.SaveChanges();
        }