public ActionResult Create(WorksViewModel model) { HttpCookie cookieReq = Request.Cookies["My localhost cookie"]; int ids = 0; if (cookieReq != null) { ids = Convert.ToInt32(cookieReq["ids"]); } else { FormsAuthentication.SignOut(); return(RedirectToActionPermanent("Index", "Works")); } model.UserId = ids; model.DateOfPublication = DateTime.Now; if (ModelState.IsValid) { WorksBO newWork = AutoMapper <WorksViewModel, WorksBO> .Map(model); workServ.Create(newWork); return(RedirectToActionPermanent("Index", "Works")); } return(View()); }
// GET: Admin/Works public ActionResult Index() { Covers covers = db.Covers.FirstOrDefault(c => c.Page == "Works"); string cover = ""; if (covers != null) { cover = db.Covers.FirstOrDefault(c => c.Page == "Works").Photo; } else { cover = null; } WorksViewModel model = new WorksViewModel() { Portfolio = new Portfolio(), Portfolios = db.Portfolio.ToList(), Cover = cover, Header = "Create new Portfolio", Action = "Create" }; return(View(model)); }
public ActionResult Update(int id) { ViewBag.GenreList = new SelectList(genreServ.GetGenres().ToList(), "Id", "Name"); WorksViewModel work = AutoMapper <WorksBO, WorksViewModel> .Map(workServ.GetWork, (int)id); return(View(work)); }
public ActionResult Update(WorksViewModel user) { WorksBO newUser = AutoMapper <WorksViewModel, WorksBO> .Map(user); workServ.Update(newUser); return(RedirectToActionPermanent("Index", "Works")); }
public MainWindow() { DbOperations.InitDatabase(); this.worksViewModel = new WorksViewModel(); InitializeComponent(); WorksItemsControl.ItemsSource = worksViewModel.GetAllWorks(); }
public NewWorkWindow(WorksViewModel worksViewModel, Work work) { this.worksViewModel = worksViewModel; this.CurrentWork = work; this.DataContext = this; InitializeComponent(); }
public ActionResult Details(int id) { WorksViewModel work = AutoMapper <WorksBO, WorksViewModel> .Map(workServ.GetWork, (int)id); work.Name = ""; work.UserId = 1; return(View(work)); }
// GET: Admin/Works/Edit/5 public ActionResult Edit(int id) { var portfolio = db.Portfolio.FirstOrDefault(p => p.id == id); if (portfolio != null) { WorksViewModel model = new WorksViewModel() { Portfolio = portfolio, Portfolios = db.Portfolio.ToList(), Cover = db.Covers.FirstOrDefault(c => c.Page == "Works").Photo, Header = "Edit Portfolio", Action = "Edit" }; return(View("Index", model)); } else { return(RedirectToAction("Index")); } }
public ActionResult Details(WorksViewModel user) { HttpCookie cookieReq = Request.Cookies["My localhost cookie"]; int ids = 0; if (cookieReq != null) { ids = Convert.ToInt32(cookieReq["ids"]); } WorksBO newUser = AutoMapper <WorksViewModel, WorksBO> .Map(user); CommentsBO newComment = new CommentsBO(); newComment.Comment = newUser.Name; newComment.WorkId = newUser.Id; newComment.UserId = ids; return(RedirectToActionPermanent("Index", "Works")); }
public ActionResult GetComments(WorksViewModel work) { HttpCookie cookieReqs = Request.Cookies["My localhost cookie"]; int idsWork = work.Id; int idsUser = 0; if (cookieReqs != null) { idsUser = Convert.ToInt32(cookieReqs["ids"]); } else { FormsAuthentication.SignOut(); } if (work.UserId != 0) { RatingsBO userRatingForWork = ratingServ.GetRatings().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault(); RatingsBO newRating = new RatingsBO(); newRating.Rank = work.UserId; newRating.UserId = idsUser; newRating.WorkId = idsWork; if (userRatingForWork != null) { RatingsBO old = ratingServ.GetRating(userRatingForWork.Id); ratingServ.DeleteRating(old.Id); ratingServ.Create(newRating); } else { ratingServ.Create(newRating); } } if (work.Name != null) { CommentsBO newComment = new CommentsBO(); newComment.Comment = work.Name; newComment.UserId = idsUser; newComment.WorkId = idsWork; CommentsBO test = commentServ.GetComments().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault(); if (commentServ.GetComments().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault() != null) { CommentsBO old = commentServ.GetComment(test.Id); commentServ.DeleteComment(old.Id); commentServ.Create(newComment); } else { commentServ.Create(newComment); } } var commentList = commentServ.GetComments().Join(workServ.GetWorks(), c => c.WorkId, w => w.Id, (c, w) => new { Id = c.Id, Comment = c.Comment, UserId = c.UserId, WorkId = c.WorkId }).Join(userServ.GetUsers(), c => c.UserId, u => u.Id, (c, u) => new InfoModelWithComments { Id = c.Id, UserName = u.Login, Comment = c.Comment, WorkId = c.WorkId, IsDelete = u.IsDelete }).ToList(); foreach (var item in commentList) { if (item.IsDelete == true) { item.UserName = "******"; } } ViewBag.CommentsList = commentList.Where(c => c.WorkId == idsWork).ToList(); List <RatingsBO> lst = ratingServ.GetRatings().Where(x => x.WorkId == idsWork).Join(userServ.GetUsers(), c => c.UserId, u => u.Id, (c, u) => new RatingsBO { Id = c.Id, Rank = c.Rank, UserId = c.UserId, WorkId = c.WorkId, IsDeleteCheck = u.IsDelete }).Where(x => x.IsDeleteCheck == false).ToList(); if (lst.Count != 0) { int sum = 0; int rating = 0; foreach (var item in lst) { sum += item.Rank; } rating = sum / lst.Count; ViewBag.Ratings = rating; } else { ViewBag.Ratings = 0; } return(View("_CommentsTable")); }
public WorksView() { InitializeComponent(); DataContext = new WorksViewModel(); }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { _vm = DataContext as WorksViewModel; }