Пример #1
0
        public async Task <IPostBatchModel> Post(IUserSession userSession, T[] collection)
        {
            var query = new LinkedList <T>();

            foreach (var primaryKeyContainer in collection)
            {
                if (primaryKeyContainer is IAuthAffectedModel affected)
                {
                    affected.UserId = userSession.UserId;
                }

                var exist = await AllReadyExist(primaryKeyContainer);

                var res = exist ?? (await Container.AddAsync(primaryKeyContainer)).Entity;
                query.AddLast(res);
            }
            await DbContext.SaveChangesAsync();

            return(new PostBatchModel()
            {
                Ids = query.Select(x => (IPostResponseModel) new PostBaseModel()
                {
                    Id = x.Id
                }).ToArray()
            });
        }