예제 #1
0
        public async Task <Boolean> deleteFruit(deleteFruitDto request)
        {
            if (!await PermissionChecker.IsGrantedAsync("Pages.Suppliers.Update"))
            {
                throw new AbpAuthorizationException("You are not authorized to do this!");
            }

            supplier s = await this.Repository.GetAsync(request.supplierId);                                            //read the supplier

            if (s == null)
            {
                throw new UserFriendlyException("Unable to find supplier");
            }
            this.ExpandSupplierEntity(s);                                                                               //load supplier fruits
            SupplierFruit sf = (s.SupplierFruits.FirstOrDefault(x => x.fruitId == request.fruitId));                    //check if fruit alreayd exists

            if (sf == null)
            {
                throw new UserFriendlyException("Supplier already got this fruit");
            }


            s.SupplierFruits.Remove(sf);


            await CurrentUnitOfWork.SaveChangesAsync();

            return(true);
        }
예제 #2
0
        public async Task <Boolean> addFruit(addFruitDto request)
        {
            if (!await PermissionChecker.IsGrantedAsync("Pages.Suppliers.Update"))
            {
                throw new AbpAuthorizationException("You are not authorized to do this!");
            }
            this.Lookupfruit(request.fruitId);                                              //check if fruit exists
            supplier s = await this.Repository.GetAsync(request.supplierId);                //read the supplier

            if (s == null)
            {
                throw new UserFriendlyException("Unable to find supplier");
            }
            this.ExpandSupplierEntity(s);                                                   //load supplier fruits
            if (s.SupplierFruits.Any(x => x.fruitId == request.fruitId))                    //check if fruit alreayd exists
            {
                throw new UserFriendlyException("Supplier already got this fruit");
            }

            SupplierFruit sf = new SupplierFruit(s)
            {
                fruitId = request.fruitId,
                Price   = request.Price,
            };

            s.SupplierFruits.Add(sf);

            await CurrentUnitOfWork.SaveChangesAsync();

            return(true);
        }