示例#1
0
        public async Task <IHttpActionResult> ProfileLanguage(ProfileLanguageModel model)
        {
            var person = SecurityPrincipal.Current;
            var role   = person.Role;

            // TODO: If this application grows into something bigger it is important to
            // refactor this into a more extensible pattern like a chain of responsibility.
            if (role.Equals("Parent", System.StringComparison.InvariantCultureIgnoreCase))
            {
                await _parentsService.UpdateParentLanguage(person.PersonUniqueId, model.LanguageCode);

                return(Ok());
            }

            await _teachersService.UpdateStaffLanguage(person.PersonUniqueId, model.LanguageCode);

            return(Ok());
        }
        //[ValidateAntiForgeryToken]
        public ActionResult TranslationMainLanguagePair(ProfileTranslationViewModel model)
        {
            var repo = new Repository<ProfileLanguageModel>(DbCollection.ProfileLanguage);
            var listItem = repo.Gets().Where(m => m.AccountId.Equals(User.Identity.GetUserId()) && m.Type.Equals(1)).ToList();
            foreach (var profileLanguageModel in listItem)
            {
                repo.Delete(profileLanguageModel.Id);
            }
            foreach (var item in model.ProfileLanguageList)
            {
                item.AccountId = User.Identity.GetUserId();
                item.Type = 1;
                repo.Insert(item);
            }
            if (string.IsNullOrEmpty(model.SourceOther) || string.IsNullOrEmpty(model.TargetOther))
                return Json(new {result = true, model});

            var other = new ProfileLanguageModel
            {
                AccountId = User.Identity.GetUserId(),
                Type = 1,
                SourceLanguage = model.SourceOther,
                TargetLanguage = model.TargetOther,
            };
            repo.Insert(other);

            return Json(new { result = true, model });
        }