public void ShowAllRating(Item item) { Console.Clear(); RatingBL ratingBL = new RatingBL(); UserBL userBL = new UserBL(); List <Rating> ratings = null; ratings = ratingBL.GetAllRating(item.ItemId); if (ratings.Count <= 0) { Console.WriteLine("Chưa có đánh giá"); Console.ReadKey(); } else { foreach (var rating in ratings) { var table = new ConsoleTable("Tên", userBL.GetUserById(rating.UserId).Username); //lấy tên user qua userBL theo Id table.AddRow("Số sao", ShowStar(rating.RatingStars)); table.AddRow("Tiêu đề", rating.RatingTitle); table.AddRow("Nội dung", rating.RatingContent); table.Write(Format.Minimal); Console.WriteLine("-------------------------------------------------------------------------"); } Console.WriteLine("Nhấn phím bất kì để tiếp tục"); Console.ReadKey(); } }
public JsonResultEntity Create([FromBody] RatingEntity ratingEntity) { RatingBL ratingBL = new RatingBL(); JsonResultEntity response = new JsonResultEntity(); try { var result = ratingBL.Create(ratingEntity); if (result.HasWarning()) { response.Message = String.Join(",", result.Warning); return(response); } response.Success = true; response.Data = result.Value; } catch (Exception ex) { response.Message = ex.Message; LoggerHelper.Error(ex); } return(response); }
public Yield PostPageRating(DreamContext context, DreamMessage request, Result <DreamMessage> response) { UserBE user = DekiContext.Current.User; if (UserBL.IsAnonymous(user)) { throw new RatingForAnonymousDeniedException(AUTHREALM, string.Empty); } PageBE page = PageBL_AuthorizePage(context, user, Permissions.READ, false); string scoreStr = context.GetParam("score"); float? score = null; if (!string.IsNullOrEmpty(scoreStr)) { float tempScore; if (!float.TryParse(scoreStr, out tempScore)) { throw new RatingInvalidArgumentException(); } score = tempScore; } RatingBL.SetRating(page, user, score); XDoc ret = RatingBL.GetRatingXml(page, user); response.Return(DreamMessage.Ok(ret)); yield break; }
public Yield GetPageRating(DreamContext context, DreamMessage request, Result <DreamMessage> response) { UserBE user = DekiContext.Current.User; PageBE page = PageBL_AuthorizePage(context, user, Permissions.READ, false); XDoc ret = RatingBL.GetRatingXml(page, user); response.Return(DreamMessage.Ok(ret)); yield break; }
public void Update(RatingBL rating) { if (null == rating) { return; } var item = AutoMapperBL <RatingBL, Rating> .Map(rating); Dbcontext.UowRepositoryRatings.Update(item); Dbcontext.Save(); }
public void Create(RatingBL rating) { if (null == rating) { return; } var item = new Rating() { Rank = rating.Rank, UserId = rating.UserId, WorkId = rating.WorkId }; Dbcontext.UowRepositoryRatings.Create(item); Dbcontext.Save(); }
public void RateItem(Item item) { Console.Clear(); RatingBL ratingBL = new RatingBL(); Rating rating = new Rating(); if (ratingBL.CheckItemRatedByUserId(user.UserId, item.ItemId) != null) { string yorN = Utility.OnlyYN("Bạn đánh giá rồi. Bạn có muốn cập nhập? (Y/N):"); switch (yorN) { case "Y": rating = Utility.MenuRating(user.UserId, item.ItemId); if (ratingBL.UpdateRateItem(rating)) { Console.WriteLine("Cập nhập đánh giá thành công"); Console.WriteLine("Nhấn phím bất kì để tiếp tục"); Console.ReadKey(); } else { Console.WriteLine("Cập nhập đánh giá không thành công"); } ShowAllRating(item); break; case "N": break; } } else { rating = Utility.MenuRating(user.UserId, item.ItemId); if (ratingBL.RateItem(rating)) { Console.WriteLine("Đánh giá thành công"); ShowAllRating(item); } else { Console.WriteLine("Đánh giá thất bại"); } } }
public JsonResultEntity Delete(int id) { var ratingBL = new RatingBL(); JsonResultEntity response = new JsonResultEntity(); try { var result = ratingBL.DeleteById(id); if (result.HasWarning()) { response.Message = String.Join(",", result.Warning); return(response); } response.Success = true; response.Data = result.Value; } catch (Exception e) { response.Message = e.Message; LoggerHelper.Error(e); } return(response); }
public override JsonResultEntity Get([FromBody] DBParamEntity dbParamEntity) { RatingBL ratingBL = new RatingBL(); JsonResultEntity response = new JsonResultEntity(); try { var result = ratingBL.GetAll(dbParamEntity); if (result.HasWarning()) { response.Message = String.Join(",", result.Warning); return(response); } var dataFound = ratingBL.GetTotalRows(dbParamEntity); var totalPages = Convert.ToInt32(Math.Ceiling(dataFound.Value / Convert.ToDouble(dbParamEntity.Limit))); response.Success = true; response.Data = result.Value; response.MetaInfo = new MetaInfoEntity { DataFound = dataFound.Value, DataPerPage = dbParamEntity.Limit, Page = dbParamEntity.Page, TotalPages = totalPages == 0 ? 1 : totalPages }; } catch (Exception ex) { response.Message = ex.Message; LoggerHelper.Error(ex); } return(response); }
public void ShowAnItem(int?idItem) { while (true) { Console.Clear(); Console.Clear(); Item item = new Item(); RatingBL ratingBL = new RatingBL(); item = itemBl.GetAnItemById(idItem); List <Rating> ratings = ratingBL.GetAllRating(item.ItemId); int rateStar = 0; if (ratings.Count > 0) { foreach (var rate in ratings) { rateStar += rate.RatingStars; } rateStar /= ratings.Count; } var table = new ConsoleTable("Tên", Convert.ToString(item.ItemName)); table.AddRow("Giá:", FormatCurrency(item.ItemPrice)); table.AddRow("Tác giả:", item.ItemAuthor); table.AddRow("Đánh giá:", ShowStar(rateStar) == " " ? "Chưa có đánh giá" : ShowStar(rateStar)); table.AddRow("Danh mục:", item.ItemCategory); table.AddRow("ISBN:", item.ItemISBN); table.AddRow("Ngày phát hành:", item.ItemPublished); table.AddRow("Nhà xuất bản:", item.ItemPublisher); table.AddRow("Ngôn ngữ:", item.ItemLanguage); table.AddRow("Số trang:", item.ItemPages); table.Write(); Console.WriteLine("Mô tả"); WriteLineWordWrap(item.ItemDescription); Console.WriteLine(); OrderBl orderBL = new OrderBl(); if (item.ItemId != orderBL.CheckItemPurchase(item.ItemId, user.UserId)) { string[] choice = { "Thêm vào giỏ hàng", "Đánh giá sản phẩm", "Xem tất cả đánh giá", "Quay lại" }; short choose = Utility.MenuDetail("Menu", choice); switch (choose) { case 1: AddToCart(item); continue; case 2: RateItem(item); continue; case 3: ShowAllRating(item); continue; case 4: break; } } else { string[] choice = { "Đánh giá sản phẩm", "Xem tất cả đánh giá", "Quay lại" }; short choose = Utility.MenuDetail("Menu", choice); switch (choose) { case 1: RateItem(item); continue; case 2: ShowAllRating(item); continue; case 3: break; } } break; } }
public void RatingDoseByVisiter([FromBody] RatingDTO rating) { RatingBL.CalcRate(rating); }
public ActionResult GetComments(WorkVM work) { HttpCookie cookieReqs = Request.Cookies["Localhost cookie"]; int idsWork = work.Id; int idsUser = 0; if (cookieReqs != null) { idsUser = Convert.ToInt32(cookieReqs["ids"]); } else { FormsAuthentication.SignOut(); } if (work.UserId != 0) { RatingBL userRatingForWork = ratingBL.GetRatings().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault(); RatingBL newRating = new RatingBL { Rank = work.UserId, UserId = idsUser, WorkId = idsWork }; if (userRatingForWork != null) { RatingBL old = ratingBL.GetRating(userRatingForWork.Id); ratingBL.DeleteRating(old.Id); ratingBL.Create(newRating); } else { ratingBL.Create(newRating); } } if (work.Name != null) { CommentBL newComment = new CommentBL(); newComment.Comment = work.Name; newComment.UserId = idsUser; newComment.WorkId = idsWork; CommentBL test = commentBL.GetComments().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault(); if (null != commentBL.GetComments().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault()) { CommentBL old = commentBL.GetComment(test.Id); commentBL.DeleteComment(old.Id); commentBL.Create(newComment); } else { commentBL.Create(newComment); } } var commentList = commentBL.GetComments().Join(workBL.GetWorks(), c => c.WorkId, w => w.Id, (c, w) => new { Id = c.Id, Comment = c.Comment, UserId = c.UserId, WorkId = c.WorkId }).Join(userBL.GetUsers(), c => c.UserId, u => u.Id, (c, u) => new UserWithCommentVM { 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 <RatingBL> lst = ratingBL.GetRatings().Where(x => x.WorkId == idsWork).Join(userBL.GetUsers(), c => c.UserId, u => u.Id, (c, u) => new RatingBL { 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")); }