Пример #1
0
        public static async Task <ActionResult <T> > Add <T, TKey>(this Controller controller, ICrudManager <T, TKey> manager, T value) where T : class where TKey : IComparable
        {
            TKey newId = await manager.Add(value);

            string newUri = controller.GetCurrentUri() + "/" + newId;

            return(controller.Created(newUri, await manager.Get(newId)));
        }
Пример #2
0
        public static async Task <IEnumerable <UriAndValue <T> > > AddIntern <T, TKey>(this Controller controller, ICrudManager <T, TKey> manager, IEnumerable <T> values)
            where T : class where TKey : IComparable
        {
            var newIds = await manager.Add(values);

            var newObjects = await manager.Get(newIds);

            string uri     = controller.GetCurrentUri("/bulk");
            var    newUris = newIds.Select(id => uri + "/" + id);
            var    results = newIds.Select((id, idx) => new UriAndValue <T>()
            {
                Uri = uri + "/" + id, Value = newObjects.ElementAt(idx)
            });

            return(results);
        }
Пример #3
0
        public static async Task <IEnumerable <UriAndValue <T> > > AddNoGetIntern <T, TKey>(
            this Controller controller,
            ICrudManager <T, TKey> manager,
            IEnumerable <T> values,
            Action <T, TKey> setIdFunc)
            where T : class where TKey : IComparable
        {
            IEnumerable <TKey> newIds = await manager.Add(values);

            Func <T, TKey, T> mySetFunc = (v, k) =>
            {
                setIdFunc(v, k);
                return(v);
            };

            string uri     = controller.GetCurrentUri("/bulk");
            var    newUris = newIds.Select(id => uri + "/" + id);
            var    results = newIds.Select((id, idx) => new UriAndValue <T>()
            {
                Uri = uri + "/" + id, Value = mySetFunc(values.ElementAt(idx), id)
            });

            return(results);
        }
Пример #4
0
 public async Task <TKey> Add(T value)
 {
     return(await _manager.Add(value));
 }