示例#1
0
            public async Task <BusinessCommentsDto> Handle(Command request, CancellationToken cancellationToken)
            {
                var business = await _context.Businesses.FindAsync(request.BusinessId);

                if (business == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { Business = "Not found" });
                }

                var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == request.Username);

                var comment = new BusinessComment
                {
                    Author    = user,
                    Business  = business,
                    Body      = request.Body,
                    CreatedAt = DateTime.Now
                };

                business.BusinessComments.Add(comment);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(_mapper.Map <BusinessCommentsDto>(comment));
                }

                throw new Exception("Problem saving changes");
            }
 public JsonResult Edit(BusinessComment model)
 {
     //更新
     if (model.BusinessCommentId > 0 && model.BusinessInfoId > 0 && model.UserId > 0)
     {
         var businessComment = _businessCommentService.GetById(model.BusinessCommentId);
         businessComment.Contents        = model.Contents;
         businessComment.LevelId         = model.LevelId;
         businessComment.RecommendDishes = model.RecommendDishes;
         businessComment.IsAnonymous     = model.IsAnonymous;
         try
         {
             _businessCommentService.Update(businessComment);
             return(Json(new { Status = Successed.Ok }, JsonRequestBehavior.AllowGet));
         }
         catch (Exception ex)
         {
             return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet));
         }
     }//插入
     else
     {
         return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet));
     }
 }
 /// <summary>
 /// 删除实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Delete(BusinessComment model)
 {
     this._repoBusinessComment.Delete(model);
 }
 /// <summary>
 /// 修改实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Update(BusinessComment model)
 {
     this._repoBusinessComment.Update(model);
 }
 public BusinessComment Insert(BusinessComment model)
 {
     return(this._repoBusinessComment.Insert(model));
 }
示例#6
0
 /// <summary>
 /// 删除实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Delete(BusinessComment model)
 {
     this._BusinessCommentBiz.Delete(model);
 }
示例#7
0
 /// <summary>
 /// 修改实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Update(BusinessComment model)
 {
     this._BusinessCommentBiz.Update(model);
 }
示例#8
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public BusinessComment Insert(BusinessComment model)
 {
     return(this._BusinessCommentBiz.Insert(model));
 }