Esempio n. 1
0
        public async Task <MessageShowDTO> GetByIdAsync(long id)
        {
            var dbmsg = await _databaseFixture.Db.OaMessage.FindByIdAsync(id);

            MessageShowDTO dto = new MessageShowDTO
            {
                Id           = dbmsg.Id,
                MsgType      = dbmsg.MsgType,
                FaceUserType = dbmsg.FaceUserType,
                Title        = dbmsg.Title,
                IsLocal      = dbmsg.IsLocal,
                TargetType   = dbmsg.TargetType,
                Link         = dbmsg.Link,
                StartTime    = dbmsg.StartTime.ToDateTime(),
                EndTime      = dbmsg.EndTime.ToDateTime(),
                IsEnable     = dbmsg.IsEnable,
                IsDel        = dbmsg.IsDel,
                MakerUserId  = dbmsg.MakerUserId,
                CreateUserId = dbmsg.CreateUserId,
                CreateTime   = dbmsg.CreateTime,
                Content      = dbmsg.Content
            };

            var users = await _databaseFixture.Db.OaMessageUser.FindAllAsync(m => m.MessageId == dto.Id);

            dto.UserIds = users.Select(m => m.UserId).ToList();

            return(dto);
        }
Esempio n. 2
0
        public async Task <IActionResult> Add([FromBody] MessageShowDTO model)
        {
            model.CreateUserId = UserIdentity.UserId;
            bool res = await _messageService.InsertAsync(model);

            return(Ok(res));
        }
Esempio n. 3
0
        public async Task <bool> UpdateAsync(MessageShowDTO model)
        {
            using (var tran = _databaseFixture.Db.BeginTransaction())
            {
                try
                {
                    var dbmodel = await _databaseFixture.Db.OaMessage.FindByIdAsync(model.Id);

                    if (dbmodel != null)
                    {
                        dbmodel.MsgType      = model.MsgType;
                        dbmodel.FaceUserType = model.FaceUserType;
                        dbmodel.Title        = model.Title;
                        dbmodel.TargetType   = model.TargetType;
                        dbmodel.Link         = model.Link;
                        dbmodel.Content      = model.Content;
                        dbmodel.StartTime    = model.StartTime == null ? 0 : model.StartTime.Value.ToTimeStamp();
                        dbmodel.EndTime      = model.EndTime == null ? 0 : model.EndTime.Value.ToTimeStamp();
                        dbmodel.IsEnable     = model.IsEnable;
                        await _databaseFixture.Db.OaMessage.UpdateAsync(dbmodel, tran);

                        //删除
                        var dbmsgUsers = await _databaseFixture.Db.OaMessageUser.FindAllAsync(m => m.MessageId == dbmodel.Id);

                        foreach (var item in dbmsgUsers)
                        {
                            await _databaseFixture.Db.OaMessageUser.DeleteAsync(item, tran);
                        }

                        //新增
                        if (model.UserIds.HasItems())
                        {
                            List <OaMessageUser> msgUsers = new List <OaMessageUser>();
                            foreach (var item in model.UserIds)
                            {
                                msgUsers.Add(new OaMessageUser
                                {
                                    MessageId = dbmodel.Id,
                                    UserId    = item
                                });
                            }
                            await _databaseFixture.Db.OaMessageUser.BulkInsertAsync(msgUsers, tran);
                        }

                        tran.Commit();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    return(false);
                }
            }
        }
Esempio n. 4
0
        public async Task <bool> UpdateAsync(MessageShowDTO model)
        {
            var uri      = API.OaMessage.UpdateAsync(_baseUrl);
            var content  = new StringContent(JsonConvert.SerializeObject(model), System.Text.Encoding.UTF8, "application/json");
            var response = await _apiClient.PostAsync(uri, content);

            response.EnsureSuccessStatusCode();
            string res = await response.Content.ReadAsStringAsync();

            return(res.ToLower() == bool.TrueString.ToLower());
        }
Esempio n. 5
0
        public async Task <bool> InsertAsync(MessageShowDTO model)
        {
            using (var tran = _databaseFixture.Db.BeginTransaction())
            {
                try
                {
                    OaMessage addMsg = new OaMessage
                    {
                        Id           = model.Id,
                        MsgType      = model.MsgType,
                        FaceUserType = model.FaceUserType,
                        Title        = model.Title,
                        IsLocal      = model.IsLocal,
                        TargetType   = model.TargetType,
                        Link         = model.Link,
                        Content      = model.Content,
                        StartTime    = model.StartTime == null ? 0 : model.StartTime.Value.ToTimeStamp(),
                        EndTime      = model.EndTime == null ? 0 : model.EndTime.Value.ToTimeStamp(),
                        IsExecuted   = 0,
                        IsEnable     = 0,
                        IsDel        = 0,
                        MakerUserId  = model.MakerUserId,
                        CreateUserId = model.CreateUserId,
                        CreateTime   = DateTime.Now.ToTimeStamp()
                    };
                    int id = await _databaseFixture.Db.OaMessage.InsertReturnIdAsync(addMsg, tran);

                    if (model.UserIds.HasItems())
                    {
                        List <OaMessageUser> msgUsers = new List <OaMessageUser>();
                        foreach (var item in model.UserIds)
                        {
                            msgUsers.Add(new OaMessageUser
                            {
                                MessageId = id,
                                UserId    = item
                            });
                        }
                        await _databaseFixture.Db.OaMessageUser.BulkInsertAsync(msgUsers, tran);
                    }

                    tran.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    return(false);
                }
            }
        }
Esempio n. 6
0
 public async Task <bool> UpdateAsync([FromBody] MessageShowDTO model)
 {
     return(await _messageService.UpdateAsync(model));
 }
Esempio n. 7
0
        public async Task <IActionResult> Update([FromBody] MessageShowDTO model)
        {
            bool res = await _messageService.UpdateAsync(model);

            return(Ok(res));
        }