public async Task <Music> CreateMusic(Music newMusic)
        {
            await _unitOfWork.Musics.AddAsync(newMusic);

            await _unitOfWork.CommitAsync();

            return(newMusic);
        }
        public async Task <ApiResult> CreateFoods(FoodsCreateDto input)
        {
            var entity = new Foods();

            entity.CreateOrUpdate();
            repository.Add(entity);
            await unitofWork.CommitAsync();

            return(ApiResult.Ok());
        }
        public async Task <ApiResult> CreateCategory(CategoryCreateDto input)
        {
            var goodsCategory = new GoodsCategory();

            goodsCategory.CreateOrUpdate(input.CategoryName, input.Sort);
            repository.Add(goodsCategory);
            if (await new UniqueGoodsCategoryNameSpecification(repository).IsSatisfiedBy(goodsCategory))
            {
                await unitofWork.CommitAsync();
            }
            return(ApiResult.Ok("商品分类创建成功"));
        }
Ejemplo n.º 4
0
        public async Task <ApiResult> CreateLimitedTimeActivitie(LimitedTimeActivitieCreateDto input)
        {
            var entity = new LimitedTimeActivitie();

            entity.CreateOrUpdate(input.ActivitieName, input.GoodsId, input.ActivitiePrice, input.StartTime, input.EndTime);
            repository.Add(entity);
            if (await new LimitedTimeActivitieValidityCheckSpecification(goodsRepository).IsSatisfiedBy(entity))
            {
                await unitofWork.CommitAsync();
            }
            return(ApiResult.Ok("活动创建成功"));
        }
Ejemplo n.º 5
0
        public async Task <ApiResult> RoleCreate(RoleCreateDto input)
        {
            using var tran = await unitofWork.BeginTransactionAsync();

            var role = new Role();

            role.SetRole(input.RoleName, input.SuperAdmin, input.Permissions);
            rolerepository.Add(role);
            if (await new PermissionValidityCheckSpecification(permissionRepository).IsSatisfiedBy(role))
            {
                await unitofWork.CommitAsync(tran);
            }
            return(ApiResult.Ok("角色创建成功"));
        }
Ejemplo n.º 6
0
 public async Task <DefaultEventHandlerResponse> EventHandleErrCatch(EventHandleRequest <EventHandlerErrDto> input)
 {
     try
     {
         var entity = input.GetData().CopyTo <EventHandlerErrDto, EventHandleErrorInfo>();
         infoRepository.Add(entity);
         await unitofWork.CommitAsync();
     }
     catch (Exception e)
     {
         logger.LogError($"事件订阅器异常处理持久化失败,异常信息:{e.Message}");
     }
     return(DefaultEventHandlerResponse.Default());
 }
 public async Task <DefaultEventHandlerResponse> InitRoleBasedAccessControler(EventHandleRequest <LoginSuccessDto> input)
 {
     return(await new DefaultEventHandlerResponse().RunAsync(nameof(InitRoleBasedAccessControler), input.GetDataJson(), async() =>
     {
         InitUserOauthDto.Github data = default;
         if (!string.IsNullOrEmpty(input.GetData().Token))
         {
             data = System.Text.Json.JsonSerializer.Deserialize <InitUserOauthDto.Github>(input.GetData().Token);
         }
         var role = new Role();
         role.SetRole("超级管理员", true);
         roleRepository.Add(role);
         var admin = new Account();
         var defpwd = "x1234567";
         admin.CreateAccount(data?.login ?? "eshopadmin", data?.name ?? "商城管理员", defpwd, Common.GetMD5SaltCode);
         if (data != null)
         {
             admin.User.CreateOrUpdateUser(data?.name ?? "商城管理员", data?.avatar_url ?? "", "", "", UserGender.Male, Convert.ToDateTime("1980-01-01"));
         }
         admin.SetRoles(new List <Guid>()
         {
             role.Id
         });
         var defbuyer = new Account();
         defbuyer.CreateAccount("eshopuser", "白云苍狗", defpwd, Common.GetMD5SaltCode);
         defbuyer.User.CreateOrUpdateUser("张老三", "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhbimg.huabanimg.com%2F0830450561b24f4573bed70d7f74bd43f39302e11bee-s2tj6i_fw658&refer=http%3A%2F%2Fhbimg.huabanimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1618110799&t=b215598f3b458ad7c08aee2b4614622b", "北京市海淀区太平路1号", "13000000000", UserGender.Male, Convert.ToDateTime("1980-01-01"));
         accountRepository.Add(admin);
         accountRepository.Add(defbuyer);
         if (await new UniqueSuperRoleSpecification(roleRepository).IsSatisfiedBy(role))
         {
             await unitofWork.CommitAsync();
         }
         await stateManager.SetState(new RoleBaseInitCheckCache(true));
     }));
Ejemplo n.º 8
0
        public async Task <Product> CrearProductoAsync(ProductModel product)
        {
            var category = await _CategoryRepository.GetAsync(x => x.CategoryName.ToLower().Equals(product.Category.ToLower()));

            if (category is null)
            {
                category = new Category {
                    CategoryName = product.Category
                }
            }
            ;

            var result = await _ProductRepository.CreateAsync(new Product
            {
                Name        = product.Name,
                Description = product.Description,
                Price       = product.Price,
                Category    = category,
                Isavalible  = true,
            });

            await _unitofWork.CommitAsync();

            return(result);
        }
Ejemplo n.º 9
0
        public async Task <T> AddAsync(T entity)
        {
            await _repository.AddAsync(entity);

            await _unitOfWork.CommitAsync();

            return(entity);
        }
        public async Task <ApiResult> SavePermissions(List <CreatePermissionDto> input)
        {
            var result = input.CopyTo <CreatePermissionDto, CreatePermissionTmpDto>();

            new PermissionMultiCreateService(repository, result).Create();
            await unitofWork.CommitAsync();

            return(await ApiResult.Ok("权限批量导入成功").Async());
        }
Ejemplo n.º 11
0
        public async Task <ApiResult> CreateOrder(OrderCreateDto input)
        {
            var mockUser = (await accountQueryService.GetMockAccount()).GetData <CurrentUser>();
            //申明一个创建订单领域服务实例,将远程rpc调用作为匿名函数传递进去
            var createOrderService = new CreateOrderService(GetGoodsListByIds, DeductionGoodsStock, UnDeductionGoodsStock);

            return(await ApiResult.Ok("订单创建成功!").RunAsync(async() =>
            {
                var order = await createOrderService.CreateOrder(mockUser.Id, mockUser.UserName, mockUser.Address, mockUser.Tel, input.Items.CopyTo <OrderCreateDto.OrderCreateItemDto, OrderItem>().ToList());//通过订单服务创建订单
                repository.Add(order);
                if (await new CheckOrderCanCreateSpecification(repository).IsSatisfiedBy(order))
                {
                    await unitofWork.CommitAsync();
                }
                await eventBus.SendEvent(EventTopicDictionary.Order.CreateOrderSucc, new OperateOrderSuccessEvent(order, mockUser.UserName)); //发送订单创建成功事件
            },
                                                                                                                                              //失败回滚
                                                          createOrderService.UnCreateOrder));
        }
        public async Task <ApiResult> CreateGoods(GoodsCreateDto input)
        {
            var goods = new Goods();

            goods.CreateOrUpdateGoods(input.GoodsName, input.GoodsImage, input.Price, input.CategoryId);
            goods.UpOrDownShelf(false);
            goods.ChangeStock(input.Stock);
            repository.Add(goods);
            if (await new GoodsValidityCheckSpecification(repository, goodsCategoryRepository).IsSatisfiedBy(goods))
            {
                if (await unitofWork.CommitAsync())
                {
                    await localEventBus.SendEvent(EventTopicDictionary.Goods.Loc_WriteToElasticsearch, goods);

                    return(ApiResult.Ok("商品创建成功"));
                }
            }
            return(ApiResult.Ok("商品创建失败"));
        }
Ejemplo n.º 13
0
 public async Task <DefaultEventHandlerResponse> ExpireCancelOrder(EventHandleRequest <OperateOrderSuccDto> input)
 {
     return(await new DefaultEventHandlerResponse().RunAsync(nameof(ExpireCancelOrder), input.GetDataJson(), async() =>
     {
         var eventData = input.GetData();
         var order = await repository.GetAsync(eventData.OrderId);
         if (order == null)
         {
             throw new ApplicationServiceException($"没有找到订单");
         }
         var cancelOrderService = new CancelOrderService(UnDeductionGoodsStock);
         if (await cancelOrderService.Cancel(order))
         {
             repository.Update(order);
             var tradeLog = new TradeLog();
             tradeLog.CreateTradeLog(TradeLogState.CancelOrder, eventData.OrderId, order.OrderNo, null, null, Guid.Empty, null);
             tradeLogRepository.Add(tradeLog);
             await unitofWork.CommitAsync();
         }
     }));
 }
        public async Task <ApiResult> Deliver(LogisticsDeliverDto input)
        {
            using var tran = await unitofWork.BeginTransactionAsync();

            var order = await orderRepository.GetAsync(input.OrderId);

            if (order == null)
            {
                throw new ApplicationServiceException("订单无效!");
            }
            var logistics   = new Logistics();
            var mallSetting = (await mallSettingQuery.GetMallSetting()).GetData <MallSettingOutInfo>();

            logistics.Deliver(input.OrderId, (LogisticsType)input.LogisticsType, input.LogisticsNo, mallSetting.DeliverName, mallSetting.DeliverAddress, HttpContextExt.Current.User.Id, order.ConsigneeInfo.Name, order.ConsigneeInfo.Address, input.DeliveTime);
            repository.Add(logistics);
            if (await new LogisticsDeliverCheckSpecification(repository).IsSatisfiedBy(logistics))
            {
                await unitofWork.CommitAsync(tran);

                await eventBus.SendEvent(EventTopicDictionary.Logistics.LogisticsDeliverSucc, new OperateLogisticsSuccessEvent(logistics, HttpContextExt.Current.User.LoginName));
            }
            return(ApiResult.Ok());
        }
Ejemplo n.º 15
0
        public override async Task SaveData(GoodsActor model, ILifetimeScope scope)
        {
            var goods = await repository.GetAsync(model.Id);

            if (goods != null)
            {
                goods.ChangeStock(model.Stock);
            }
            repository.Update(goods);
            await localEventBus.SendEvent(EventTopicDictionary.Goods.Loc_WriteToElasticsearch, goods);

            await unitofWork.CommitAsync();

            await Task.CompletedTask;
        }
Ejemplo n.º 16
0
        public async Task <ApiResult> CreateOrUpdateMallSetting(CreateOrUpdateMallSettingDto input)
        {
            var entity = await repository.GetAsync() ?? new MallSetting();

            entity.CreateOrUpdate(input.ShopName, input.ShopDescription, input.ShopIconUrl, input.Notice, input.DeliverName, input.DeliverAddress);
            if (await repository.AnyAsync())
            {
                repository.Update(entity);
            }
            else
            {
                repository.Add(entity);
            }
            await unitofWork.CommitAsync();

            return(ApiResult.Ok());
        }
Ejemplo n.º 17
0
        public async Task <ApiResult> AccountRegister(CreateAccountDto input)
        {
            using var tran = await unitofWork.BeginTransactionAsync();

            var account = new Account();

            account.CreateAccount(input.LoginName, input.NickName, input.Password, Common.GetMD5SaltCode);
            accountRepository.Add(account);
            if (await new UniqueAccountIdSpecification(accountRepository).IsSatisfiedBy(account))
            {
                await unitofWork.CommitAsync(tran);
            }
            return(ApiResult.Ok("用户注册成功"));
        }
Ejemplo n.º 18
0
        public async Task DeleteArtist(Artist artist)
        {
            _unitOfWork.Artists.Remove(artist);

            await _unitOfWork.CommitAsync();
        }
Ejemplo n.º 19
0
 public async Task <DefaultEventHandlerResponse> EventHandleSetDefMallSetting(EventHandleRequest <string> input)
 {
     return(await new DefaultEventHandlerResponse().RunAsync(nameof(EventHandleSetDefMallSetting), input.GetDataJson(), async() =>
     {
         var categorys = new List <GoodsCategory>()
         {
             new GoodsCategory()
             {
                 CategoryName = "精选热菜", Sort = 0
             },
             new GoodsCategory()
             {
                 CategoryName = "爽口凉菜", Sort = 1
             },
             new GoodsCategory()
             {
                 CategoryName = "小吃主食", Sort = 2
             },
             new GoodsCategory()
             {
                 CategoryName = "特色粥品", Sort = 3
             }
         };
         categoryRepository.Add(categorys[0]);
         categoryRepository.Add(categorys[1]);
         categoryRepository.Add(categorys[2]);
         categoryRepository.Add(categorys[3]);
         var willSend = new List <Goods>();
         Goods createGoods(string name, string url, decimal price, Guid categoryid)
         {
             var goods = new Goods();
             goods.CreateOrUpdateGoods(name, url, price, categoryid);
             goods.UpOrDownShelf(true);
             goods.ChangeStock(100);
             repository.Add(goods);
             willSend.Add(goods);
             return goods;
         }
         void createLimit(Goods goods)
         {
             var entity = new LimitedTimeActivitie();
             entity.CreateOrUpdate(goods.GoodsName, goods.Id, goods.Price - new Random(Guid.NewGuid().GetHashCode()).Next(1, 4), DateTime.Now, DateTime.Now.AddDays(30));
             entity.UpOrDownShelf(true);
             limitrepository.Add(entity);
         }
         createGoods("娃娃菜炖豆腐", "http://fuss10.elemecdn.com/d/2d/b1eb45b305635d9dd04ddf157165fjpeg.jpeg?imageView2/1/w/114/h/114", 17, categorys[0].Id);
         createGoods("手撕包菜", "http://fuss10.elemecdn.com/9/c6/f3bc84468820121112e79583c24efjpeg.jpeg?imageView2/1/w/114/h/114", 16, categorys[0].Id);
         var goods1 = createGoods("香酥黄金鱼/3条", "http://fuss10.elemecdn.com/4/e7/8277a6a2ea0a2e97710290499fc41jpeg.jpeg?imageView2/1/w/114/h/114", 11, categorys[0].Id);
         createGoods("八宝酱菜", "http://fuss10.elemecdn.com/9/b5/469d8854f9a3a03797933fd01398bjpeg.jpeg?imageView2/1/w/114/h/114", 4, categorys[1].Id);
         createGoods("拍黄瓜", "http://fuss10.elemecdn.com/6/54/f654985b4e185f06eb07f8fa2b2e8jpeg.jpeg?imageView2/1/w/114/h/114", 9, categorys[1].Id);
         createGoods("扁豆焖面", "http://fuss10.elemecdn.com/c/6b/29e3d29b0db63d36f7c500bca31d8jpeg.jpeg?imageView2/1/w/114/h/114", 14, categorys[2].Id);
         createGoods("葱花饼", "http://fuss10.elemecdn.com/f/28/a51e7b18751bcdf871648a23fd3b4jpeg.jpeg?imageView2/1/w/114/h/114", 10, categorys[2].Id);
         var goods2 = createGoods("牛肉馅饼", "http://fuss10.elemecdn.com/d/b9/bcab0e8ad97758e65ae5a62b2664ejpeg.jpeg?imageView2/1/w/114/h/114", 14, categorys[2].Id);
         createGoods("招牌猪肉白菜锅贴/10个", "http://fuss10.elemecdn.com/7/72/9a580c1462ca1e4d3c07e112bc035jpeg.jpeg?imageView2/1/w/114/h/114", 7, categorys[2].Id);
         createGoods("皮蛋瘦肉粥", "http://fuss10.elemecdn.com/c/cd/c12745ed8a5171e13b427dbc39401jpeg.jpeg?imageView2/1/w/114/h/114", 10, categorys[3].Id);
         var goods3 = createGoods("红豆薏米美肤粥", "http://fuss10.elemecdn.com/d/22/260bd78ee6ac6051136c5447fe307jpeg.jpeg?imageView2/1/w/114/h/114", 12, categorys[3].Id);
         createGoods("红枣山药糙米粥", "http://fuss10.elemecdn.com/9/b5/469d8854f9a3a03797933fd01398bjpeg.jpeg?imageView2/1/w/114/h/114", 10, categorys[3].Id);
         var goods4 = createGoods("鲜蔬菌菇粥", "http://fuss10.elemecdn.com/e/a3/5317c68dd618929b6ac05804e429ajpeg.jpeg?imageView2/1/w/114/h/114", 11, categorys[3].Id);
         createLimit(goods1);
         createLimit(goods2);
         createLimit(goods3);
         createLimit(goods4);
         if (await unitofWork.CommitAsync())
         {
             await localEventBus.SendEvent(EventTopicDictionary.Goods.Loc_WriteToElasticsearch, willSend);
         }
     }));