private static void InitializeAutoMapper() { Mapper.Initialize( cfg => cfg.CreateMap <Postdb, Post>() .AfterMap((s, d) => { //Author IStudentDbRepository <Studentdb> rStudents = new StudentDbRepository(); Studentdb studentdb = rStudents.Get(s.StudentId); d.Author = $"{studentdb.FirstName} {studentdb.LastName}"; //Commentsdb ICommentDbRepository <Commentdb> rCommentsdb = new CommentDbRepository(); IEnumerable <Commentdb> commentsdb = rCommentsdb.GetAll(s.Id); // List <Comment> comments = new List <Comment>(); //Commentdb+Author foreach (var commentdb in commentsdb) { Comment comment = new Comment() { Id = commentdb.Id, Content = commentdb.Content, Created = commentdb.Created }; Studentdb student = rStudents.Get(commentdb.StudentId); comment.Author = $"{student.FirstName} {student.LastName}"; comments.Add(comment); } // d.Comments = comments; //Tags ITagDbRepository <Tagdb> rTags = new TagDbRepository(); d.Tags = rTags.GetAll(s.Id); })); }
public ActionResult Login() { ModelState.AddModelError("", "Вы не авторизованы"); Studentdb studentdb = new Studentdb() { FirstName = "Alex", LastName = "M" }; return(View(studentdb)); }
// GET: Home public ActionResult Index() { if (null == Session["StudentId"]) { ModelState.AddModelError("", "Вы не авторизованы"); return(RedirectToAction("Login")); } else { int id; int.TryParse(Session["StudentId"].ToString(), out id); Studentdb student = repositoryStudent.Get(id); ModelState.AddModelError("", $"Ваш пользователь: {student.FirstName} {student.LastName}"); } // var posts = Mapper.Map <IEnumerable <Postdb>, IEnumerable <Post> >(repository.GetAll()); return(View(posts)); }
public ActionResult Login(Studentdb model) { if (ModelState.IsValid) { Studentdb student = repositoryStudent.Get(model); if (student == null) { repositoryStudent.Create(model); repositoryStudent.Save(); Studentdb ss = repositoryStudent.Get(model); Session["StudentId"] = ss.Id; } else { Session["StudentId"] = student.Id.ToString(); } return(RedirectToAction("Index")); } return(View(model)); }