public void TranslationViewModel_GetsDefaultTranslation() { var c = new Collection(); c.Notes = "Notas"; c.Translations.Add(new CollectionTranslation { LanguageCode = "pt", Description = "Português" }); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en"); var vm = new TranslatedViewModel<Collection, CollectionTranslation>(c); Assert.AreEqual("Português", vm.Translation.Description); }
// GET: /BackOffice/Collection/Create public async Task<ActionResult> Create(int authorId = 0) { var model = new CollectionEditViewModel(); var c = new Collection(); c.Translations.Add(new CollectionTranslation { LanguageCode = LanguageDefinitions.DefaultLanguage }); if (authorId != 0) { c.Authors = await db.Set<Author>().Where(a => a.Id == authorId).ToListAsync(); } return View(GenerateViewModel(c)); }
private bool DoesCodeAlreadyExist(Collection col) { return db.Entities .Any(d => d.CatalogCode == col.CatalogCode && d.Id != col.Id); }
private CollectionEditViewModel GenerateViewModel(Collection c) { var vm = new CollectionEditViewModel(); vm.Collection = c; var authorIds = c.Authors.Select(a => a.Id).ToList(); vm.AvailableAuthors = db.Set<Author>() .Select(a => new SelectListItem { Value = a.Id.ToString(), Text = a.LastName + ", " + a.FirstName, Selected = authorIds.Contains(a.Id) }) .ToList(); return vm; }