public ActionResult Create(BadgeCategoryViewModel model) { var badgeCategoryToCreate = new BadgeCategory { Name = model.Name }; var badgeImage = _fileService.Save(model.File, publicAccess: true); badgeCategoryToCreate.ImageUrl = badgeImage.Uri.AbsoluteUri; if (ModelState.IsValid) { RepositoryFactory.BadgeCategoryRepository.EnsurePersistent(badgeCategoryToCreate); Message = "BadgeCategory Created Successfully"; return(RedirectToAction("Index")); } else { var viewModel = BadgeCategoryViewModel.Create(Repository); viewModel.Name = model.Name; return(View(viewModel)); } }
public ActionResult Delete(Guid id, BadgeCategory badgeCategory) { var badgeCategoryToDelete = RepositoryFactory.BadgeCategoryRepository.GetNullableById(id); if (badgeCategoryToDelete == null) return RedirectToAction("Index"); RepositoryFactory.BadgeCategoryRepository.Remove(badgeCategoryToDelete); Message = "BadgeCategory Removed Successfully"; return RedirectToAction("Index"); }
public ActionResult Delete(Guid id, BadgeCategory badgeCategory) { var badgeCategoryToDelete = RepositoryFactory.BadgeCategoryRepository.GetNullableById(id); if (badgeCategoryToDelete == null) { return(RedirectToAction("Index")); } RepositoryFactory.BadgeCategoryRepository.Remove(badgeCategoryToDelete); Message = "BadgeCategory Removed Successfully"; return(RedirectToAction("Index")); }
public async Task AddBadgeCategoryAsync(string title, string description) { var alreadyExists = await _badgeCategoriesDbSet .AnyAsync(t => t.Title == title); if (alreadyExists) { throw new ValidationException(ErrorCodes.DuplicatesIntolerable, $"Badge category {title} already exists"); } var entity = new BadgeCategory { Title = title, Description = description }; _badgeCategoriesDbSet.Add(entity); await SaveChangesAsync(); }
public ActionResult Create(BadgeCategoryViewModel model) { var badgeCategoryToCreate = new BadgeCategory {Name = model.Name}; var badgeImage = _fileService.Save(model.File, publicAccess: true); badgeCategoryToCreate.ImageUrl = badgeImage.Uri.AbsoluteUri; if (ModelState.IsValid) { RepositoryFactory.BadgeCategoryRepository.EnsurePersistent(badgeCategoryToCreate); Message = "BadgeCategory Created Successfully"; return RedirectToAction("Index"); } else { var viewModel = BadgeCategoryViewModel.Create(Repository); viewModel.Name = model.Name; return View(viewModel); } }
private static void PopulateDb(FluentConfiguration config) { using (var session = config.BuildSessionFactory().OpenSession()) { using (var tx = session.BeginTransaction()) { PopulateLookups(session); var studentRole = new Role(RoleNames.Student) {Name = "Student"}; var instructorRole = new Role(RoleNames.Instructor) {Name = "Instructor"}; var adminRole = new Role(RoleNames.Administrator) {Name = "Administrator"}; session.SaveOrUpdate(studentRole); session.SaveOrUpdate(instructorRole); session.SaveOrUpdate(adminRole); var user = new User {Identifier = "postit"}; user.Profile = new Profile(user) { FirstName = "Scott", LastName = "Kirkland", Email = "*****@*****.**", ImageUrl = WebConfigurationManager.AppSettings["DefaultProfilePictureUrl"] }; user.Roles.Add(studentRole); session.SaveOrUpdate(user); var hermes = new User {Identifier = "hconrad"}; hermes.AssociateProfile(new Profile(hermes) { FirstName = "Hermes", LastName = "Conrad", Email = "*****@*****.**", ImageUrl = WebConfigurationManager.AppSettings["DefaultProfilePictureUrl"] }); hermes.Roles.Add(instructorRole); session.SaveOrUpdate(hermes); var farnsworth = new User { Identifier = "hfarnsworth" }; farnsworth.AssociateProfile(new Profile(farnsworth) { FirstName = "Hubert", LastName = "Farnsworth", Email = "*****@*****.**", ImageUrl = WebConfigurationManager.AppSettings["DefaultProfilePictureUrl"] }); session.SaveOrUpdate(farnsworth); var instructor = new Instructor { FirstName = "Hubert", LastName = "Farnsworth", Email = "*****@*****.**", Identifier = "hfarnworth", User = farnsworth }; var instructor2 = new Instructor { FirstName = "Hermes", LastName = "Conrad", Email = "*****@*****.**", Identifier = "hconrad", User = hermes }; session.SaveOrUpdate(instructor); session.SaveOrUpdate(instructor2); var etype = new ExperienceType { Name = "Exploration", Icon = "icon-flag" }; session.SaveOrUpdate(etype); session.SaveOrUpdate(new ExperienceType {Name = "Collaboration", Icon = "icon-group"}); var outcome = new Outcome {Name = "Outcome 1", Description = "Some outcome", ImageUrl = string.Empty}; session.SaveOrUpdate(outcome); session.SaveOrUpdate(new Outcome { Name = "Super Skills", Description = "Pretty good skillz", ImageUrl = string.Empty }); var experience = new Experience { Creator = user, ExperienceType = etype, Name = "Sample Experience", Description = "This is a bit of text about exactly what I did in this experience", Start = DateTime.Now, Location = "moab, ut", CoverImageUrl = "https://ucdbadges.blob.core.windows.net/publicimagesdev/e600f3de-a969-45af-b70b-7d2f5285e572" }; experience.AddInstructor(instructor); experience.AddInstructor(instructor2); session.SaveOrUpdate(experience); //Badges var category = new BadgeCategory { Name = "SampleCategory", ImageUrl = "https://ucdbadges.blob.core.windows.net/publicimagesdev/12da4d70-207a-45e5-b6e4-f1b418c1802a" }; session.SaveOrUpdate(category); var badge = new Badge { Approved = true, Category = category, CreatedOn = DateTime.UtcNow, Name = "First Badge", Description = "Really interesting badge for being awesome", Creator = user, ImageUrl = "https://ucdbadges.blob.core.windows.net/publicimagesdev/12da4d70-207a-45e5-b6e4-f1b418c1802a" }; badge.AddCriteria("You need to do a, b, c"); badge.AddCriteria("Also you need to be a human"); session.SaveOrUpdate(badge); tx.Commit(); } } }
public ActionResult BadgeCategorySave(BadgeCategory b) { BadgeCategory badgeCategory; if (b.Id == null || b.Id == Guid.Empty) { badgeCategory = new BadgeCategory(); db.BadgeCategories.Add(badgeCategory); } else { badgeCategory = db.BadgeCategories.FirstOrDefault(x => x.Id == b.Id); } badgeCategory.CategoryName = b.CategoryName; badgeCategory.CategoryDescription = b.CategoryDescription; db.SaveChanges(); return RedirectClient("/Mentor/BadgeCategories"); }
public ActionResult BadgeCategoryAdd() { BadgeCategory newBadgeCategory = new BadgeCategory(); return View("BadgeCategory", newBadgeCategory); }
private static void PopulateDb(FluentConfiguration config) { using (var session = config.BuildSessionFactory().OpenSession()) { using (var tx = session.BeginTransaction()) { PopulateLookups(session); var studentRole = new Role(RoleNames.Student) { Name = "Student" }; var instructorRole = new Role(RoleNames.Instructor) { Name = "Instructor" }; var adminRole = new Role(RoleNames.Administrator) { Name = "Administrator" }; session.SaveOrUpdate(studentRole); session.SaveOrUpdate(instructorRole); session.SaveOrUpdate(adminRole); var user = new User { Identifier = "postit" }; user.Profile = new Profile(user) { FirstName = "Scott", LastName = "Kirkland", Email = "*****@*****.**", ImageUrl = WebConfigurationManager.AppSettings["DefaultProfilePictureUrl"] }; user.Roles.Add(studentRole); session.SaveOrUpdate(user); var hermes = new User { Identifier = "hconrad" }; hermes.AssociateProfile(new Profile(hermes) { FirstName = "Hermes", LastName = "Conrad", Email = "*****@*****.**", ImageUrl = WebConfigurationManager.AppSettings["DefaultProfilePictureUrl"] }); hermes.Roles.Add(instructorRole); session.SaveOrUpdate(hermes); var farnsworth = new User { Identifier = "hfarnsworth" }; farnsworth.AssociateProfile(new Profile(farnsworth) { FirstName = "Hubert", LastName = "Farnsworth", Email = "*****@*****.**", ImageUrl = WebConfigurationManager.AppSettings["DefaultProfilePictureUrl"] }); session.SaveOrUpdate(farnsworth); var instructor = new Instructor { FirstName = "Hubert", LastName = "Farnsworth", Email = "*****@*****.**", Identifier = "hfarnworth", User = farnsworth }; var instructor2 = new Instructor { FirstName = "Hermes", LastName = "Conrad", Email = "*****@*****.**", Identifier = "hconrad", User = hermes }; session.SaveOrUpdate(instructor); session.SaveOrUpdate(instructor2); var etype = new ExperienceType { Name = "Exploration", Icon = "icon-flag" }; session.SaveOrUpdate(etype); session.SaveOrUpdate(new ExperienceType { Name = "Collaboration", Icon = "icon-group" }); var outcome = new Outcome { Name = "Outcome 1", Description = "Some outcome", ImageUrl = string.Empty }; session.SaveOrUpdate(outcome); session.SaveOrUpdate(new Outcome { Name = "Super Skills", Description = "Pretty good skillz", ImageUrl = string.Empty }); var experience = new Experience { Creator = user, ExperienceType = etype, Name = "Sample Experience", Description = "This is a bit of text about exactly what I did in this experience", Start = DateTime.Now, Location = "moab, ut", CoverImageUrl = "https://ucdbadges.blob.core.windows.net/publicimagesdev/e600f3de-a969-45af-b70b-7d2f5285e572" }; experience.AddInstructor(instructor); experience.AddInstructor(instructor2); session.SaveOrUpdate(experience); //Badges var category = new BadgeCategory { Name = "SampleCategory", ImageUrl = "https://ucdbadges.blob.core.windows.net/publicimagesdev/12da4d70-207a-45e5-b6e4-f1b418c1802a" }; session.SaveOrUpdate(category); var badge = new Badge { Approved = true, Category = category, CreatedOn = DateTime.UtcNow, Name = "First Badge", Description = "Really interesting badge for being awesome", Creator = user, ImageUrl = "https://ucdbadges.blob.core.windows.net/publicimagesdev/12da4d70-207a-45e5-b6e4-f1b418c1802a" }; badge.AddCriteria("You need to do a, b, c"); badge.AddCriteria("Also you need to be a human"); session.SaveOrUpdate(badge); tx.Commit(); } } }