Пример #1
0
        public bool Insert(CommonPicture model)
        {
            try
            {
                using (var context = new YueDongEntities())
                {
                    context.CommonPictures.Add(model);

                    return context.SaveChanges() > 0;
                }
            }
            catch (Exception e)
            {

            }
            return false;
        }
Пример #2
0
 public IHttpActionResult Replay([FromBody] Message message)
 {
     var result = new BaseResult();
     result.ResultCode = "1";
     result.ResultMessage = "Error";
     if (message.MessageContent == null)
     {
         result.ResultMessage = "消息内容不能为空";
         return Ok(result);
     }
     if (message.Batch == null)
     {
         result.ResultMessage = "消息号不能为空";
         return Ok(result);
     }
     Data.Model.Message newMessage = new Data.Model.Message();
     newMessage.Id = Guid.NewGuid();
     newMessage.CreateTime = DateTime.Now;
     newMessage.Status = 1;
     newMessage.Text = message.MessageContent;
     newMessage.FromWho = message.FromWho;
     newMessage.ToWho = message.ToWho;
     newMessage.MessageBatch = message.Batch;
     if (message.Picture != null && message.Picture.Length > 0)
     {
         CommonPicture pic = new CommonPicture();
         pic.Id = Guid.NewGuid();
         pic.CreateTime = DateTime.Now;
         pic.FileData = message.Picture;
         pic.Status = 1;
         pic.UserId = message.FromWho;
         new CommonPictureDAL().Insert(pic);
         newMessage.PicId = pic.Id;
     }
     var re = new MessageDAL().Insert(newMessage);
     if (re)
     {
         result.ResultCode = "0";
         result.ResultMessage = "Success";
         result.ResultData = new
         {
             Batch = newMessage.MessageBatch,
             FromWho = new CommonUserDAL().GetSingleById(newMessage.FromWho.Value).NickName,
             ToWho = new CommonUserDAL().GetSingleById(newMessage.ToWho.Value).NickName,
             CreateTime = newMessage.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss"),
             Text = newMessage.Text,
             FromId = newMessage.FromWho,
             ToId = newMessage.ToWho
         };
     }
     else
     {
         result.ResultMessage = "发送消息失败";
     }
     return Ok(result);
 }
Пример #3
0
        public bool Update(CommonPicture model)
        {
            try
            {
                using (var context = new YueDongEntities())
                {
                    var result = context.CommonPictures.FirstOrDefault(a => a.Id == model.Id);
                    if (result != null)
                    {
                        result.CreateTime = model.CreateTime;
                        result.FileData = model.FileData;
                        result.UserId = model.UserId;
                    }
                    return context.SaveChanges() > 0;
                }
            }
            catch (Exception e)
            {

            }
            return false;
        }