Exemple #1
0
        /// <summary>
        /// 根据酒店评论id获取酒店评论
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public HotelComment GetHotelCommentByKey(Guid hotelId, Guid id)
        {
            JXHotelDbContext dbContext    = this.EFContext.dbContext as JXHotelDbContext;
            HotelComment     hotelComment = dbContext.Hotels.Find(hotelId).HotelComments.Where(account => account.Id.Equals(id)).FirstOrDefault();

            return(hotelComment);
        }
        public void Create_ShouldCreateNewCommentCorrectly()
        {
            int    hotelId  = 1;
            string username = "******";

            this.dbContext.Hotels.Add(new Hotel {
                Id = hotelId
            });
            this.dbContext.Users.Add(new MbUser {
                UserName = username
            });
            this.dbContext.SaveChanges();

            string content = "testContent";

            this.hotelCommentsService.Create(hotelId, content, username);
            HotelComment result = this.dbContext.HotelComments.First();

            result.ShouldSatisfyAllConditions
            (
                () => result.HotelId.ShouldBe(hotelId),
                () => result.Content.ShouldBe(content),
                () => result.User.UserName.ShouldBe(username)
            );
        }
Exemple #3
0
        public void Delete(int commentId)
        {
            HotelComment comment = this.GetById(commentId);

            comment.IsDeleted = true;
            this.dbContext.SaveChanges();
        }
Exemple #4
0
        public bool CheckForExistingLike(int commentId, string username)
        {
            HotelComment comment = this.GetById(commentId);
            MbUser       user    = this.usersService.GetByUsername(username);

            bool result = this.dbContext.HotelCommentLikes.Any(x => x.HotelComment == comment && x.User == user);

            return(result);
        }
Exemple #5
0
        public void Like(int commentId, string username)
        {
            HotelComment comment = this.GetById(commentId);
            MbUser       user    = this.usersService.GetByUsername(username);

            var like = new HotelCommentLike
            {
                HotelComment = comment,
                User         = user,
            };

            this.dbContext.HotelCommentLikes.Add(like);
            this.dbContext.SaveChanges();
        }
Exemple #6
0
        public IActionResult HotelComment(string hotelComment, int hotelCommentScore, int hotelId)
        {
            int?         userID       = HttpContext.Session.GetInt32("UserId");
            HotelComment hotelcomment = new HotelComment();

            hotelcomment.HotelId = hotelId;
            hotelcomment.UserId  = userID;
            hotelcomment.Comment = hotelComment;
            hotelcomment.Score   = hotelCommentScore;
            HotelBusiness business = new HotelBusiness();

            business.AddHotelComment(hotelcomment);
            return(RedirectToAction("Index", "Hotel"));
        }
Exemple #7
0
        public void Dislike(int commentId, string username)
        {
            HotelComment comment = this.GetById(commentId);
            MbUser       user    = this.usersService.GetByUsername(username);

            var like = this.dbContext.HotelCommentLikes.SingleOrDefault(x => x.HotelComment == comment && x.User == user);

            if (like == null)
            {
                throw new LikeNullException();
            }

            this.dbContext.HotelCommentLikes.Remove(like);
            this.dbContext.SaveChanges();
        }
Exemple #8
0
        public HotelComment GetById(int commentId)
        {
            HotelComment comment = this.dbContext.HotelComments.FirstOrDefault(x => x.Id == commentId);

            if (comment == null)
            {
                throw new CommentNullException();
            }

            if (comment.IsDeleted == true)
            {
                throw new CommentDeletedException();
            }

            return(comment);
        }
Exemple #9
0
        public async Task <object> Put(string id, [FromBody] HotelComment model)
        {
            var obj = hostelContext.PersonEmploys.FirstOrDefault(d => d.GUID == id);

            if (obj != null)
            {
                obj.Status   = 0;
                obj.Evaluate = model.Evaluate;
                obj.Comment  = model.Comment;
            }
            try
            {
                hostelContext.PersonOrders.RemoveRange(hostelContext.PersonOrders.Where(d => d.PersonId == obj.PersonId));
                var person = hostelContext.ServicePersons.FirstOrDefault(d => d.Id == obj.PersonId);
                var order  = hostelContext.HotelOrders.Where(d => d.Id == obj.HotelOrderId).Select(d => new
                {
                    HotelName       = d.Hotel.Name,
                    HotelGUID       = d.Hotel.GUID,
                    HotelDepartment = d.Department.DepartmentName,
                    HotelWork       = d.WorkType.Name
                }).FirstOrDefault();
                hostelContext.Messages.Add(new HostelModel.MessageModel()
                {
                    Context = $"{order.HotelName} 于 {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 终止 了您的{order.HotelDepartment}-{order.HotelWork}的工作!",
                    From    = order.HotelGUID,
                    To      = person?.GUID,
                    Type    = "工作终止"
                });

                hostelContext.SaveChanges();
                NoticeCommon notice = new NoticeCommon(options);


                await notice.SendNotice(new MessageWeb.Models.NoticeModel()
                {
                    Type  = "解聘",
                    Phone = hostelContext.ServicePersons.FirstOrDefault(d => d.Id == obj.PersonId)?.Phone,
                    Hotel = hostelContext.HotelOrders.FirstOrDefault(d => d.Id == obj.HotelOrderId)?.Hotel?.Name ?? "酒店"
                });

                return(new { state = true, message = "操作成功" });
            }
            catch (Exception)
            {
                return(new { state = false, message = "数据操作服务器错误,请确认数据是否完整" });
            }
        }
Exemple #10
0
        public HotelComment AddHotelComment(HotelComment hotelcomment)
        {
            var context = new HotelDBContext();

            try
            {
                if (hotelcomment.Id == 0)
                {
                    context.HotelComment.Add(hotelcomment);
                }
                context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(hotelcomment);
        }
Exemple #11
0
        public void Create(int hotelId, string content, string username)
        {
            if (string.IsNullOrWhiteSpace(content))
            {
                throw new ArgumentNullException(nameof(content));
            }

            MbUser user  = this.usersService.GetByUsername(username);
            Hotel  hotel = this.hotelsService.GetById(hotelId);

            var hotelComment = new HotelComment
            {
                Content = content,
                Hotel   = hotel,
                User    = user,
            };

            this.dbContext.HotelComments.Add(hotelComment);
            this.dbContext.SaveChanges();
        }
Exemple #12
0
        public HotelComment AddHotelComment(HotelComment hotelcomment)
        {
            HotelRepository repository = new HotelRepository();

            return(repository.AddHotelComment(hotelcomment));
        }
Exemple #13
0
        /// <summary>
        /// 根据酒店评论id获取酒店评论
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public HotelCommentDataObject GetHotelCommentByKey(Guid hotelId, Guid id)
        {
            HotelComment hotelComment = hotelRepository.GetHotelCommentByKey(hotelId, id);

            return(AutoMapper.Mapper.Map <HotelComment, HotelCommentDataObject>(hotelComment));
        }