Beispiel #1
0
 public static async Task <ActionResult <IEnumerable <UriAndValue <T> > > > AddNoGet <T, TKey>(
     this Controller controller,
     ICRUDManager <T, TKey> manager,
     IEnumerable <T> values,
     Action <T, TKey> setIdFunc)
     where T : class where TKey : IComparable
 {
     return(controller.Ok(await AddNoGetIntern(controller, manager, values, setIdFunc)));
 }
Beispiel #2
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);
        }
 protected GetService(ICRUDManager <T, TKey> manager)
 {
     _manager = manager ?? throw new ArgumentNullException(nameof(manager));
 }
Beispiel #4
0
        public static async Task <ActionResult> Delete <T, TKey>(this Controller controller, ICRUDManager <T, TKey> manager, IEnumerable <TKey> ids) where T : class where TKey : IComparable
        {
            await manager.Delete(ids);

            return(controller.NoContent());
        }
Beispiel #5
0
        public static async Task <ActionResult> Update <T, TKey>(this Controller controller, ICRUDManager <T, TKey> manager, TKey idFromUri, TKey idFromValue, T value)
            where T : class where TKey : IComparable
        {
            if (idFromUri.CompareTo(idFromValue) != 0)
            {
                return(controller.BadRequest("Mismatch between id and dto.Id"));
            }

            await manager.Update(value);

            return(controller.NoContent());
        }
Beispiel #6
0
        public static async Task <ActionResult <T> > AddNoGet <T, TKey>(this Controller controller, ICRUDManager <T, TKey> manager, T value, Action <T, TKey> setIdFunc)
            where T : class where TKey : IComparable
        {
            TKey newId = await manager.Add(value);

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

            setIdFunc(value, newId);
            return(controller.Created(newUri, value));
        }
Beispiel #7
0
 public static async Task <ActionResult <UrisAndValues <T> > > Add2 <T, TKey>(this Controller controller, ICRUDManager <T, TKey> manager, IEnumerable <T> values)
     where T : class where TKey : IComparable
 {
     return(controller.Ok((await AddIntern(controller, manager, values)).ToUrisAndValues()));
 }
Beispiel #8
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);
        }
Beispiel #9
0
 protected CRUDService(ICRUDManager <T, TKey> manager) : base(manager)
 {
     _manager = manager ?? throw new ArgumentNullException();
 }