Esempio n. 1
0
        public ETravelFeed AddTravelFeed(ETravelFeed travelFeed)
        {
            using (var dmTrans = _rep.GetTransaction())
            {
                try
                {
                    var tran = dmTrans.BeginTransaction();
                    EMedia media = null;
                    if (travelFeed.ExtMediaFileJson.HasValue())
                    {
                        media = new EMedia()
                        {
                            MediaFiles = travelFeed.ExtMediaFileJson,
                            CreateTime = DateTime.Now
                        };
                        _rep.Add(media, tran);
                    }

                    if (media != null)
                    {
                        travelFeed.FeedMediaId = media.Id;
                    }
                    travelFeed.CreateTime = DateTime.Now;
                    _rep.Add(travelFeed, tran);

                    dmTrans.Commit();
                }
                catch
                {
                    dmTrans.Rollback();
                    throw;
                }
            }

            return _rep.Query<ETravelFeed, EUser, EMedia, ETravelFeed>()
                .LeftJoin<EUser>((tf, u) => tf.UserId == u.Id)
                .LeftJoin<EMedia>((tf, m) => tf.FeedMediaId == m.Id)
                .Where(p => p.Id == travelFeed.Id)
                .Select(
                    (tf, u, m) =>
                        new Columns(
                            tf,
                            u.NickName.As("ExtNickName"),
                            u.UserAvatar.As("ExtUserAvatar"),
                            m.MediaFiles.As("ExtMediaFileJson")))
                .Single();
        }
Esempio n. 2
0
 public ActionResult AddTravelFeed(ETravelFeed travelFeed)
 {
     travelFeed.UserId = Passport.User.Id;
     var newTravelFeed = _travelService.AddTravelFeed(travelFeed);
     return JsonResult(newTravelFeed, "发表成功");
 }