public void Setup()
        {
            this.WebElem = new WebElement();
            this.WebElementTrans = new WebElementTranslation();

            this.WebElemModel = new WebElementModel();
            this.WebElemModelTrans = new WebElementTranslationModel();
        }
        public void Setup()
        {
            WebElement rc = new WebElement
            {
                WebElementId = 1,
                ModelName = this.ModelName,
                PropertyName = this.PropertyName,
                WebElementTranslations = new List<WebElementTranslation>
            {
                    new WebElementTranslation
                    {
                        Language = SupportedLanguage.English,
                        TranslatedText = "InEngHelp",
                        TranslationType = TranslatedTextType.SubLabel
                    },
                    new WebElementTranslation
                    {
                        Language = SupportedLanguage.English,
                        TranslatedText = "InEng",
                        TranslationType = TranslatedTextType.Label
                    },
                    new WebElementTranslation
                    {
                        Language = SupportedLanguage.Finnish,
                        TranslatedText = "InFi",
                        TranslationType = TranslatedTextType.Label
                    },
                     new WebElementTranslation
                    {
                        Language = SupportedLanguage.Swedish,
                        TranslatedText = "InSv",
                        TranslationType = TranslatedTextType.ControlText
                    }
                }
            };

            this.rcList = new List<WebElement>();
            this.rcList.Add(rc);

            this.mG = new Mock<IGeneralDataHelper>();
            this.mG.Setup(o => o.Get(It.IsAny<Expression<Func<WebElement, bool>>>()))
               .Returns<Expression<Func<WebElement, bool>>>(predicate => this.rcList.FirstOrDefault(predicate.Compile()));

            this.localEdit = new LocalizationEditor(this.mG.Object);
        }
        private void AddUpdateWebelement(string ModelName, string PropertyName, List<WebElementTranslation> WebTransList)
        {
            WebElement webE = new WebElement
            {
                ModelName = ModelName,
                PropertyName = PropertyName,
                WebElementTranslations = WebTransList
            };

            var dbElem = this.dbH.Get<WebElement>(o => o.ModelName == ModelName & o.PropertyName == PropertyName);

            if (dbElem != null)
            {
                foreach (var item in webE.WebElementTranslations)
                {
                    WebElementTranslation text = dbElem.WebElementTranslations.Where(o => o.TranslationType == item.TranslationType & o.Language == item.Language).FirstOrDefault();
                    item.WebElementId = dbElem.WebElementId;

                    if (text == null)
                    {
                        this.dbH.Create<WebElementTranslation>(item);

                        Console.WriteLine("Create WebElementTranslation");
                        this.dbH.FlushChanges();
                        this.UpdateCounter++;
                    }
                    else
                    {
                        if (item.TranslatedText != text.TranslatedText)
                        {
                            text.TranslatedText = item.TranslatedText;
                            this.dbH.Update<WebElementTranslation>(text);

                            Console.WriteLine("Update WebElementTranslation");
                            this.dbH.FlushChanges();
                            this.UpdateCounter++;
                        }
                    }
                }
            }
            else
            {
                this.dbH.Create<WebElement>(webE);
                this.dbH.FlushChanges();

                Console.WriteLine("Created: " + webE.PropertyName);

                this.NewCounter++;
            }
        }
        /// <summary>
        /// Method to add new translations to new Webelement object (when creating it)
        /// </summary>
        /// <param name="model">View model that contains translations in one language for particular WebElement</param>
        /// <param name="dbWebElement">Database object to be saved</param>
        private void CreateWebObjectTranslations(Web.WebElementModel model, WebElement dbWebElement)
        {
            if (!string.IsNullOrEmpty(model.PropertyLabel))
            {
                dbWebElement.WebElementTranslations.Add(
                    new WebElementTranslation { Language = model.LanguageToSave.ToDbObject(), TranslatedText = model.PropertyLabel, TranslationType = TranslatedTextType.Label });
            }

            if (!string.IsNullOrEmpty(model.PropertySubLabel))
            {
                dbWebElement.WebElementTranslations.Add(
                    new WebElementTranslation { Language = model.LanguageToSave.ToDbObject(), TranslatedText = model.PropertySubLabel, TranslationType = TranslatedTextType.SubLabel });
            }

            if (!string.IsNullOrEmpty(model.PropertyHint))
            {
                dbWebElement.WebElementTranslations.Add(
                    new WebElementTranslation { Language = model.LanguageToSave.ToDbObject(), TranslatedText = model.PropertyHint, TranslationType = TranslatedTextType.ControlText });
            }

            if (!string.IsNullOrEmpty(model.PropertyHelp))
            {
                dbWebElement.WebElementTranslations.Add(
                    new WebElementTranslation { Language = model.LanguageToSave.ToDbObject(), TranslatedText = model.PropertyHelp, TranslationType = TranslatedTextType.HelpText });
            }

            if (!string.IsNullOrEmpty(model.PropertyEnum))
            {
                dbWebElement.WebElementTranslations.Add(
                    new WebElementTranslation { Language = model.LanguageToSave.ToDbObject(), TranslatedText = model.PropertyEnum, TranslationType = TranslatedTextType.EnumText });
            }
        }
        /// <summary>
        /// Method that decides whether WebElement has specified type/langu
        /// </summary>
        /// <param name="elementToUpdate">Page translation and either updates/creates/deletes it depending on actual translation string</param>
        /// <param name="model">Model for translation updating</param>
        /// <param name="textType">Type of the text</param>
        private void AddOrUpdateWebObjectTranslation(WebElement elementToUpdate, Web.WebElementModel model, TranslatedTextType textType)
        {
            string valueToUpdate = string.Empty;
            switch (textType)
            {
                case TranslatedTextType.Label:
                    valueToUpdate = model.PropertyLabel;
                    break;
                case TranslatedTextType.SubLabel:
                    valueToUpdate = model.PropertySubLabel;
                    break;
                case TranslatedTextType.ControlText:
                    valueToUpdate = model.PropertyHint;
                    break;
                case TranslatedTextType.HelpText:
                    valueToUpdate = model.PropertyHelp;
                    break;
                case TranslatedTextType.EnumText:
                    valueToUpdate = model.PropertyEnum;
                    break;
            }

            var dbTranslation = elementToUpdate.WebElementTranslations.SingleOrDefault(
                                wt => wt.TranslationType == textType && wt.Language == model.LanguageToSave.ToDbObject());

            if (!string.IsNullOrEmpty(valueToUpdate))
            {
                if (dbTranslation == null)
                {
                    // add element
                    elementToUpdate.WebElementTranslations.Add(
                        new WebElementTranslation { Language = model.LanguageToSave.ToDbObject(), TranslatedText = valueToUpdate, TranslationType = textType });
                }
                else
                {
                    // update element
                    dbTranslation.TranslatedText = valueToUpdate;
                }
            }
            else
            {
                if (dbTranslation != null)
                {
                    // remove element
                    elementToUpdate.WebElementTranslations.Remove(dbTranslation);
                }
            }
        }
        /// <summary>
        /// Method save WebElementModel object. If this is new model then new WebElement with childrens will be created
        /// If TranslatedText property will be empty it it will be deleted from DB. If TranslatedText is not empty then updated.
        /// After entity updates changes will be forced to update entity
        /// </summary>
        /// <param name="model">WebElementModel object model</param>
        public void SaveResources(Web.WebElementModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model", "model passed for saving is null");
            }

            if (model.WebElementId == 0)
            {
                // Creating new Web Element translation object, becaus no ID == no DB record
                var dbWebElement = new WebElement
                {
                    ModelName = model.ModelName,
                    PropertyName = model.PropertyName,
                    WebElementId = model.WebElementId,
                    WebElementTranslations = new List<WebElementTranslation>()
                };

                this.CreateWebObjectTranslations(model, dbWebElement);
                this.DbContext.Create<WebElement>(dbWebElement);
            }
            else
            {
                var dbWebElement = this.DbContext.Get<WebElement>(o => o.WebElementId == model.WebElementId);

                if (dbWebElement == null)
                {
                    throw new EserviceException("WebElement translation cannot be reloaded for edited data saving anymore");
                }

                this.AddOrUpdateWebObjectTranslation(dbWebElement, model, TranslatedTextType.Label);
                this.AddOrUpdateWebObjectTranslation(dbWebElement, model, TranslatedTextType.SubLabel);
                this.AddOrUpdateWebObjectTranslation(dbWebElement, model, TranslatedTextType.ControlText);
                this.AddOrUpdateWebObjectTranslation(dbWebElement, model, TranslatedTextType.HelpText);
                this.AddOrUpdateWebObjectTranslation(dbWebElement, model, TranslatedTextType.EnumText);

                this.DbContext.Update<WebElement>(dbWebElement);
            }
        }