Loading
 
I am doing move data from old version to new version base on nopcommerce

multilanguage and data access with nopcommerce for widget plugin full source code


Nopcommerce use code first entity framework. 
Nopcommerce plugin with data access can read here 

if you dont know how to write plugin in nopcommecer plz click here to read 

full source code download here

DataAccessClass.cs (code first entity framework) in  this file for defind entity and table, also repository (CRUD) . 
Entity class SampleTableInDb will be mapping to talbe "SampleTableInDb" by class SampleTableInDbMap
DbContext class SampleTableInDbContext to create table by call method Install() 
class DependencyRegistrer to register DbContext and Repository (CURD) to work with table SampleTableInDb

SampleDataAccessController.cs in this file for defind Localized data for model
class SampleBackEndModel the model for edit create ...
SampleBackEndLocalizeModel defind the property need to be localize (input as multi-language)


1st your entity should inherit multilang (localize interface)
public class SampleTableInDb: BaseEntity, ILocalizedEntity
    {
        public string Name { get; set; }

model for multilang
 public class SampleBackEndLocalizeModel : ILocalizedModelLocal
    {
       public int LanguageId { get; set; }


declare model when edit or create 
  public class SampleBackEndModel : ILocalizedModel<SampleBackEndLocalizeModel>
    {
        public SampleBackEndModel()
        {
            Locales = new List<SampleBackEndLocalizeModel>();
        }
        public IList<SampleBackEndLocalizeModel> Locales { get; set; }
  
In load page (Action HttpGet) need to do  this to bind existed data store in localizedproperty table
  //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name = sampleObj.GetLocalized(x => x.Name, languageId, false, false);
                locale.Version = sampleObj.GetLocalized(x => x.Version, languageId, false, false);
            });
Post (Action HttpPost) to save data into table localizedpropety
  //locales
      protected void UpdateLocales(SampleTableInDb obj, SampleBackEndModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(obj,
                    x => x.Name,
                    localized.Name,
                    localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(obj,
                    x => x.Version,
                    localized.Version,
                    localized.LanguageId);
            }
        }

In file cshtml to render multi lang input
  <div>
        @(Html.LocalizedEditor<SampleBackEndModel, SampleBackEndLocalizeModel>("product-info-localized",
    @<div class="adminContent">
        <div>Name</div>
        <div>@Html.EditorFor(model => model.Locales[item].Name, "RichEditor")</div>
        <div>Version</div>
        <div>@Html.EditorFor(model => model.Locales[item].Version)</div>
         @Html.HiddenFor(model => model.Locales[item].LanguageId)
    </div>
                ,
    @<div class="adminContent">
        <div>Name</div>
        <div>
            @Html.EditorFor(x => x.Name, "RichEditor")
        </div>
        <div>Version</div>
        <div>
            @Html.EditorFor(model => model.Version):
        </div>
    </div>
      ))
    </div>

you will see similar to bellow


$0.00