コード例 #1
0
        public async Task <object> AddCollection(Collection entity)
        {
            var entityEntry = collectionDBCotext.Collections.Add(entity);
            await collectionDBCotext.SaveChangesAsync();

            return(new
            {
                id = entityEntry.Entity.Id,
                title = entity.Title,
            });
        }
コード例 #2
0
        /// <summary>
        /// 修改 Url 内容
        /// </summary>
        /// <param name="id"></param>
        /// <param name="url"></param>
        /// <param name="title"></param>
        /// <returns></returns>

        public async Task ModifyCollection(int id, string url, string title, int?typeId = null)
        {
            var userId = GetUserId();

            try
            {
                var collection = await loveCollectionAppService.CollectionQuery(userId)
                                 .Where(t => t.Id == id)
                                 .FirstOrDefaultAsync();

                collection.Url   = url;
                collection.Title = title;
                if (typeId.HasValue)
                {
                    collection.TypeId = typeId.Value;
                }
                await _collectionDBCotext.SaveChangesAsync();
            }
            catch (Exception)
            {
                await loveCollectionAppService.UpdateAllTypeToRedisAsync(userId);

                throw;
            }
            finally
            {
                await loveCollectionAppService.UpdateAllCollectionToRedisAsync(userId);
            }
        }