当具有多语言数据库设计时,Mvc更新多对多关系

时间:2017-10-06 14:51:22

标签: jquery mysql asp.net-mvc performance entity-framework-6

我使用mvc5使用实体框架6.0和mysql data.entity 6.9.9,这个问题是整天的大脑扭转。

以下是我创建类别的代码

[HttpPost]
public JsonResult CategoryAdd(CategoryModel category, int Lang_Id)
{
    var dbCategory = _categoryrepo.GetAll().Select(x => x.CategoryName.Trim().ToUpper());
    if (ModelState.IsValid)
    {
        if (dbCategory.Contains(category.CategoryName.Trim().ToUpper()))
        {

            return Json(new ResultJson { Success = false, Message = "This Category already created ! Please Try again..." });
        }
        try
        {
            category CatModel = new category
            {

                CategoryName = category.CategoryName,
                IsActive = true

            };
            _categoryrepo.Insert(CatModel);
            _categoryrepo.Save();
            var languagecount = db.language.Where(x => x.IsActive == true).ToList();
            foreach (var LangCount in languagecount)
            {
                category_translation model = new category_translation()
                {
                    CategoryName = category.CategoryName,
                    category_ID = CatModel.ID,
                    language_ID = LangCount.ID,
                    urlFriendly = StringOperations.URLFriendly(CatModel.CategoryName)
                };
                db.category_translation.Add(model);
                db.SaveChanges();
            }
            category_translation updateCategoryTranslation = db.category_translation.Where(r => r.language_ID == Lang_Id && r.category_ID == CatModel.ID).SingleOrDefault();
            updateCategoryTranslation.language_ID = Lang_Id;
            updateCategoryTranslation.CategoryName = category.CategoryTranlatedText;
            updateCategoryTranslation.urlFriendly = StringOperations.URLFriendly(category.CategoryTranlatedText);
            db.SaveChanges();


            return Json(new ResultJson {Success = true, Message = "'"+ CatModel.CategoryName +"'" + " Created Successfully "});
        }
        catch (Exception ex) //Logging will be included by Elmah
        {
            return Json(new ResultJson {Success = false, Message = "Error Occured When Trying to Create Category! Please try again or contact with tour administrator..."});
        }
    }
    return Json(new ResultJson { Success = false, Message = "While you are Creating the category you might be entered wrong values! Please Try Again..." });
}

当然,我认为使用jvery进行mvc验证。

现在我有48个表来为它们添加值,它们与很多很多相关。 让我们假设将来我添加了208个表,每个表都有多语言选项将数据保存到数据库

示例表:
the table

问题:我应该使用异步任务执行保存方法,还是实施不会对系统造成太多影响

提示:至少有12个用户同时保存数据。

注意:我知道它太少可能只是一个问题,如果项目会增长,用户将超过100并且表格超过400.会发生什么?

0 个答案:

没有答案