// GET: /JobScrappingDefinition/Create/siteUrl=siteurl&amazonId=1
        public ActionResult Create(string siteUrl, string amazonId)
        {
            var url = HttpUtility.UrlDecode(siteUrl);
            var selectedSite =
                      _repository.GetScrappingSiteByUrl(siteUrl)
                   ?? new ScrappingSite {Name = url, Url = url};
            if (selectedSite.ScrappingSiteId == 0)
            {
                _repository.InsertScrappingSite(selectedSite);
            }

            var selectedUser =
                _repository.GetUserByAmazonId(amazonId)
                ?? new User {AmazonId = amazonId};
            if (selectedUser.UserId == 0)
            {
                _repository.InsertUser(selectedUser);
            }

            _repository.SaveAll();

            var scrappingFields = _repository.GetScrappingFields().ToList();
            var scrappingFieldEntries =
                scrappingFields
                    .Select(sf =>
                        new ScrappingFieldEntry
                        {
                            ScrappingFieldId = sf.ScrappingFieldId,
                            ScrappingField = sf
                        });

            var scrappingEntry = new CreateScrappingViewModel
            {
                ScrappingFields = scrappingFieldEntries.ToList()
                                    .Select(e => new ScrappingFieldViewModel
                                    {
                                        FieldId = e.ScrappingFieldId,
                                        FieldName = e.ScrappingField.Name
                                    }).ToList(),
                UserId = selectedUser.UserId,
                Site =
                    new ScrappingSiteViewModel
                    {
                        SiteId = selectedSite.ScrappingSiteId,
                        SiteName = selectedSite.Name,
                        SiteUrl = selectedSite.Url
                    }
            };

            return View(scrappingEntry);
        }
        public ActionResult Create(CreateScrappingViewModel scrappingEntry)
        {
            if (ModelState.IsValid)
            {
                var modelEntry = new ScrappingEntry
                {
                    EntryUserId = scrappingEntry.UserId,
                    ScrappingSiteId = scrappingEntry.Site.SiteId,
                    ScrappingFieldEntries =
                        scrappingEntry.ScrappingFields
                            .Select(f => new ScrappingFieldEntry
                            {
                                ScrappingFieldId = f.FieldId,
                                Value = f.FieldValue
                            }).ToArray()
                };

                _repository.InsertScrappingDefinitionEntry(modelEntry);
                _repository.SaveAll();

                return RedirectToAction("Index");
            }

            //TODO - load scrapping site here
            return View(scrappingEntry);
        }
        //
        // GET: /JobScrappingDefinition/Edit/5
        public ActionResult Edit(int id = 0)
        {
            ScrappingEntry scrappingdefinitionentry = _repository.GetScrappingDefinitionEntry(id);
            if (scrappingdefinitionentry == null)
            {
                return HttpNotFound();
            }

            var selectedSite = scrappingdefinitionentry.ScrappingSite;
            var scrappingEntry = new CreateScrappingViewModel
            {
                ScrappingFields = scrappingdefinitionentry.ScrappingFieldEntries.ToList()
                                    .Select(e => new ScrappingFieldViewModel
                                    {
                                        FieldId = e.ScrappingFieldId,
                                        FieldName = e.ScrappingField.Name,
                                        FieldValue = e.Value
                                    }).ToList(),
                UserId = scrappingdefinitionentry.EntryUserId,
                Site =
                    new ScrappingSiteViewModel
                    {
                        SiteId = selectedSite.ScrappingSiteId,
                        SiteName = selectedSite.Name,
                        SiteUrl = selectedSite.Url
                    }
            };

            return View(scrappingEntry);
        }