//Return Register view public ActionResult AddCorkboard() { var categoryType = categoryDbContext.CorkboardCategories.ToList(); var viewModel = new AddCorkboardVewModel { CorkboardCategories = categoryType }; return(View(viewModel)); }
public ActionResult SaveCorkboard(AddCorkboardVewModel corkboardDetails) { if (corkboardDetails.VisibilityTypeId.ToString().Equals("Private")) { if (ModelState.IsValid) { //create database context using Entity framework using (corkboardDbContext) { User user = userDbContext.Users.Where(query => query.Email.Equals(User.Identity.Name) && query.Password.Equals(corkboardDetails.Pin)).SingleOrDefault(); if (user != null) { CorkboardCategory corkboardCategory = categoryDbContext. CorkboardCategories. Where(query => query.Id.Equals(corkboardDetails.CategoryTypeId)) .SingleOrDefault(); Corkboard corkboard = new Corkboard(); corkboard.UserId = user.Id; corkboard.Title = corkboardDetails.Title; corkboard.CategoryId = corkboardCategory.Id; corkboard.VisibilityId = 1; corkboard.Watch = 0; corkboard.DateTime = DateTime.Now; corkboardDbContext.Corkboards.Add(corkboard); corkboardDbContext.SaveChanges(); } else { var categoryType = categoryDbContext.CorkboardCategories.ToList(); var viewModel = new AddCorkboardVewModel { CorkboardCategories = categoryType }; ModelState.AddModelError("Failure", "Wrong Password!"); return(View("AddCorkboard", viewModel)); } } } else { var categoryType = categoryDbContext.CorkboardCategories.ToList(); var viewModel = new AddCorkboardVewModel { CorkboardCategories = categoryType }; return(View("AddCorkboard", viewModel)); } } else if (corkboardDetails.VisibilityTypeId.ToString().Equals("Public")) { //create database context using Entity framework using (corkboardDbContext) { Corkboard corkboard = new Corkboard(); CorkboardCategory corkboardCategory = categoryDbContext. CorkboardCategories. Where(query => query.Id.Equals(corkboardDetails.CategoryTypeId)) .SingleOrDefault(); string Email = User.Identity.Name; User user = userDbContext.Users.Where(query => query.Email.Equals(Email)).SingleOrDefault(); corkboard.UserId = user.Id; corkboard.Title = corkboardDetails.Title; corkboard.CategoryId = corkboardCategory.Id; corkboard.VisibilityId = 0; corkboard.Watch = 0; corkboard.DateTime = DateTime.Now; corkboardDbContext.Corkboards.Add(corkboard); corkboardDbContext.SaveChanges(); } } else { var categoryType = categoryDbContext.CorkboardCategories.ToList(); var viewModel = new AddCorkboardVewModel { CorkboardCategories = categoryType }; return(View("AddCorkboard", viewModel)); } ViewBag.Message = "New CorkBoard has been added saved"; return(RedirectToAction("Index", "CorkBoard")); }