コード例 #1
0
        /// <summary>
        /// Создать системный чат
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <BaseApiResponse <int> > CreateSystemChat(CreateSystemChat model)
        {
            var validation = ValidateModel(model);

            if (!validation.IsSucceeded)
            {
                return(new BaseApiResponse <int>(validation));
            }

            validation = ValidationUtils.CheckIsNullOrEmpty(model.UserIds);

            if (!validation.IsSucceeded)
            {
                return(new BaseApiResponse <int>(validation));
            }

            var ticks = DateTime.UtcNow.Ticks;

            var chat = new EccChat
            {
                ChatName      = model.ChatName,
                Type          = model.ChatType,
                IsDialog      = false,
                IsArchived    = false,
                IsSystem      = true,
                UserRelations = model.UserIds.Select(x => new EccChatUserRelation
                {
                    IsChatCreator     = false,
                    UserId            = x,
                    LastVisitUtcTicks = ticks
                }).ToList()
            };

            CreateHandled(chat);

            var result = await TrySaveChangesAndReturnResultAsync("Ok");

            if (!result.IsSucceeded)
            {
                return(new BaseApiResponse <int>(result));
            }

            return(new BaseApiResponse <int>(true, "Системный чат создан", chat.Id));
        }