コード例 #1
0
        public async Task <ActionResultResponse <string> > InsertWarehouseManagerConfig(string tenantId, string warehouseId, string creatorId, string creatorFullName,
                                                                                        string creatorAvatar, WarehouseManagerConfigMeta warehouseManagerConfigMeta)
        {
            var isWarehouseExists = await _warehouseRepository.CheckExists(warehouseId, tenantId);

            if (!isWarehouseExists)
            {
                return(new ActionResultResponse <string>(-1, _warehouseResourceService.GetString("Warehouse does not exists.")));
            }
            // Todo Bo sung them dieu kien check trung theo user sau

            var info = await _warehouseManagerConfigRepository.GetInfo(warehouseId, warehouseManagerConfigMeta.UserId, true);

            if (info != null)
            {
                return(new ActionResultResponse <string>(-2, _warehouseResourceService.GetString("Warehouse manager config already exists.")));
            }

            var warehosueInfoHasDelete = await _warehouseManagerConfigRepository.GetInfo(warehouseId, warehouseManagerConfigMeta.UserId, tenantId);

            if (warehosueInfoHasDelete != null)
            {
                warehosueInfoHasDelete.IsDelete = false;
                await _warehouseManagerConfigRepository.Update(info);

                return(new ActionResultResponse <string>(1, _warehouseResourceService.GetString("Add new warehouse manager config successful."),
                                                         string.Empty, warehouseManagerConfigMeta.UserId));
            }

            var warehouseManagerConfig = new WarehouseManagerConfig
            {
                TenantId        = tenantId,
                WarehouseId     = warehouseId,
                UserId          = warehouseManagerConfigMeta.UserId.Trim(),
                FullName        = warehouseManagerConfigMeta.FullName.Trim(),
                Avatar          = warehouseManagerConfigMeta.Avatar?.Trim(),
                PhoneNumber     = warehouseManagerConfigMeta.PhoneNumber?.Trim(),
                UnsignName      = warehouseManagerConfigMeta.FullName?.StripVietnameseChars().ToUpper(),
                Permissions     = warehouseManagerConfigMeta.Permissions,
                CreatorId       = creatorId,
                CreatorFullName = creatorFullName
            };

            var result = await _warehouseManagerConfigRepository.Insert(warehouseManagerConfig);

            if (result <= 0)
            {
                return(new ActionResultResponse <string>(result,
                                                         _sharedResourceService.GetString(ErrorMessage.SomethingWentWrong)));
            }

            return(new ActionResultResponse <string>(1, _warehouseResourceService.GetString("Add new warehouse manager config successful."),
                                                     string.Empty, warehouseManagerConfigMeta.UserId));
        }
コード例 #2
0
        public async Task <ActionResultResponse <string> > Insert(string tenantId, string creatorId, string creatorFullName, string creatorAvatar,
                                                                  InventoryMeta inventoryMeta, bool isBalance = false)
        {
            var isWarehouseExists =
                await _warehouseRepository.CheckExists(inventoryMeta.WarehouseId, tenantId);

            if (!isWarehouseExists)
            {
                return(new ActionResultResponse <string>(-1, _warehouseResourceService.GetString("Warehouse does not exists. Please check again.")));
            }

            var inventory = new Inventory
            {
                WarehouseId     = inventoryMeta.WarehouseId,
                InventoryDate   = inventoryMeta.InventoryDate,
                Note            = inventoryMeta.Note,
                Status          = InventoryStatus.Waiting,
                TenantId        = tenantId,
                CreatorId       = creatorId,
                CreatorFullName = creatorFullName
            };

            inventory.InventoryDetails = await AddInventoryDetails(tenantId, inventory.WarehouseId, inventory.InventoryDate,
                                                                   inventory.Id, inventoryMeta.Details);
            await AddInventoryMembers();

            if (inventory.InventoryDetails.Count == 0)
            {
                return(new ActionResultResponse <string>(-2, _sharedResourceService.GetString(ValidatorMessage.PleaseSelect,
                                                                                              _warehouseResourceService.GetString("product"))));
            }

            var result = await _inventoryRepository.Insert(inventory);

            if (result <= 0)
            {
                return(new ActionResultResponse <string>(result,
                                                         _sharedResourceService.GetString(ErrorMessage.SomethingWentWrong)));
            }

            await Balance();

            return(new ActionResultResponse <string>(result, _sharedResourceService.GetString(SuccessMessage.AddSuccessful,
                                                                                              _warehouseResourceService.GetString("inventory"))));

            #region Local functions
            async Task AddInventoryMembers()
            {
                var httpService = new HttpClientService();

                foreach (var member in inventoryMeta.Members)
                {
                    //var userInfo = await httpService.GetUserInfo(inventory.TenantId, member.UserId);
                    //if (userInfo == null)
                    //    continue;

                    inventory.InventoryMembers.Add(new InventoryMember
                    {
                        //UserId = userInfo.UserId,
                        //FullName = userInfo.FullName,
                        //Avatar = userInfo.Avatar,
                        //OfficeName = userInfo.OfficeName,
                        //PositionName = userInfo.PositionName,
                        InventoryId = inventory.Id
                    });
                }
            }

            async Task Balance()
            {
                if (isBalance)
                {
                    // Thêm phiếu nhập và xuất để cân bằng kho.
                    await BalanceWarehouse(inventory.TenantId, inventory.Id);
                }
            }

            #endregion Local functions
        }