public async Task <APIResult> GetByUserId(int id)
        {
            var rs = await companyQueries.GetByUserIdAsync(id);

            return(new APIResult()
            {
                Result = 0,
                Data = rs
            });
        }
        public override async Task <IEnumerable <MaterialHistoryInfomation> > HandleCommand(GetAllMaterialHistoryCommand request, CancellationToken cancellationToken)
        {
            var company = await _companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var lst = (await _materialHistoryQueries.GetAllAsync(request.Model));

            return(lst);
        }
        public override async Task <IEnumerable <AccountSingleRole> > HandleCommand(GetAllAccountPartnerCommand request, CancellationToken cancellationToken)
        {
            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var lst = (await accountQueries.GetAllAsync(company?.Id));

            return(lst);
        }
        public override async Task <IEnumerable <Material> > HandleCommand(GetCommonMaterialCommand request, CancellationToken cancellationToken)
        {
            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var lst = (await materialQueries.GetsAsync(company?.Id));

            return(lst);
        }
        public override async Task <int> HandleCommand(InsertProductionCommand request, CancellationToken cancellationToken)
        {
            var id = 0;

            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        var gTIN = await gTINService.InsertOrUpdateGTINAsync(company.Id, request.Model.GTIN, request.LoginSession);

                        request.Model.GTINId = gTIN.Id;

                        request.Model.PartnerId    = company.Id;
                        request.Model.CreatedDate  = DateTime.Now;
                        request.Model.CreatedBy    = request.LoginSession.Id;
                        request.Model.ModifiedDate = DateTime.Now;
                        request.Model.ModifiedBy   = request.LoginSession.Id;

                        id = await productionRepository.AddAsync(request.Model);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (id > 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }

            return(id);
        }
        public override async Task <GTIN> HandleCommand(CalculateCheckDigitGTINCommand request, CancellationToken cancellationToken)
        {
            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var gTIN = (await gTINService.CalculateCheckDigitAsync(request.Model)).ToInformation();

            gTIN.Code = await gTINService.GetCodeGTINAsync(gTIN);

            return(gTIN);
        }
        public override async Task <int> HandleCommand(InsertMaterialCommand request, CancellationToken cancellationToken)
        {
            var company = await _companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var id = 0;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        request.Model.ParnerId     = company.Id;
                        request.Model.CreatedDate  = DateTime.Now;
                        request.Model.CreatedBy    = request.LoginSession.Id;
                        request.Model.ModifiedDate = DateTime.Now;
                        request.Model.ModifiedBy   = request.LoginSession.Id;

                        id = await _materialRepository.AddAsync((Material)request.Model);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (id > 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }

            return(id);
        }
示例#8
0
        public override async Task <AccountSingleRole> HandleCommand(GetByIdAccountPartnerCommand request, CancellationToken cancellationToken)
        {
            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var rs = await accountQueries.GetByIdAsync(request.Model);

            if (rs == null)
            {
                throw new BusinessException("Account.NotExist");
            }

            return(rs);
        }
        public override async Task <string> HandleCommand(GenerateCodeMaterialCommand request, CancellationToken cancellationToken)
        {
            var company = await _companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var rs = await _materialService.GenerateCodeAsync(company.Id);

            if (rs == null)
            {
                throw new BusinessException("Material.NotExist");
            }

            return(rs);
        }
示例#10
0
        public override async Task <MaterialHistory> HandleCommand(GetByIdMaterialHistoryCommand request, CancellationToken cancellationToken)
        {
            var company = await _companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var rs = await _materialHistoryQueries.GetByIdAsync(request.Model);

            if (rs == null)
            {
                throw new BusinessException("MaterialHistory.NotExist");
            }

            return(rs);
        }
示例#11
0
        public override async Task <int> HandleCommand(CheckNewGTINCommand request, CancellationToken cancellationToken)
        {
            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var rs = await gTINService.CheckNewGTINAsync(company.Id, request.Model, request.LoginSession);

            var ex = rs.GetException();

            if (ex != null)
            {
                throw ex;
            }
            return(0);
        }
        public override async Task <IEnumerable <Production> > HandleCommand(GetAllProductionCommand request, CancellationToken cancellationToken)
        {
            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var lst = (await productionQueries.GetAllAsync(company?.Id)).ToList();

            foreach (var item in lst)
            {
                if (item.GTIN != null)
                {
                    item.GTIN.Code = await gTINService.GetCodeGTINAsync(item.GTIN);
                }
            }

            return(lst);
        }
示例#13
0
        public override async Task <Production> HandleCommand(GetByIdProductionCommand request, CancellationToken cancellationToken)
        {
            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var rs = await productionQueries.GetByIdAsync(request.Model);

            if (rs == null)
            {
                throw new BusinessException("Production.NotExist");
            }
            if (rs.GTIN != null)
            {
                rs.GTIN.Code = await gTINService.GetCodeGTINAsync(rs.GTIN);
            }
            return(rs);
        }
        public override async Task <GTINInformation> HandleCommand(InsertOrUpdateGTINCommand request, CancellationToken cancellationToken)
        {
            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            GTIN gTIN = (await gTINService.InsertOrUpdateGTINAsync(company.Id, request.Model, request.LoginSession)).ToInformation();

            if (gTIN == null)
            {
                throw new BusinessException("Common.TaskFailed");
            }

            var rs = gTIN.ToInformation();

            rs.Code = await gTINService.GetCodeGTINAsync(gTIN);

            return(rs);
        }
示例#15
0
        public override async Task <ProcessInformation> HandleCommand(NewProcessCommand request, CancellationToken cancellationToken)
        {
            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                bool isThrownEx = false;
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        return(await processService.NewProcessAsync(company.Id, request.LoginSession));
                    }
                    catch (Exception ex)
                    {
                        isThrownEx = true;
                        throw ex;
                    }
                    finally
                    {
                        if (!isThrownEx)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }
        }
示例#16
0
        public override async Task <int> HandleCommand(UpdateAccountPartnerCommand request, CancellationToken cancellationToken)
        {
            var company = await _companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            AccountSingleRole account = null;

            if (request.Model == null || request.Model.Id == 0)
            {
                throw new BusinessException("Account.NotExisted");
            }
            else
            {
                account = await _accountQueries.GetByIdAsync(request.Model.Id);

                if (account == null)
                {
                    throw new BusinessException("Account.NotExisted");
                }
                else if (account.PartnerId != company.Id)
                {
                    throw new BusinessException("Common.NoPermission");
                }
            }

            if ((await _roleQueries.GetByIdAsync(request.Model.RoleId ?? 0)) == null)
            {
                throw new BusinessException("Role.NotSelected");
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        account.UserName       = request.Model.UserName;
                        account.Email          = request.Model.Email;
                        account.IsActived      = request.Model.IsActived;
                        account.IsExternalUser = request.Model.IsExternalUser;
                        account.IsUsed         = request.Model.IsUsed;

                        account.ModifiedDate = DateTime.Now;
                        account.ModifiedBy   = request.LoginSession.Id;
                        if (!string.IsNullOrWhiteSpace(request.Model.NewPassword))
                        {
                            account.Password = (request.Model.NewPassword + account.SecurityPassword.ToString()).CalculateMD5Hash();
                        }


                        if (await _accountRepository.UpdateAsync(account) > 0)
                        {
                            rs = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }
            return(rs);
        }
        public override async Task <int> HandleCommand(DeleteMaterialCommand request, CancellationToken cancellationToken)
        {
            var company = await _companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            Account material = null;

            if (request.Model == 0)
            {
                throw new BusinessException("Account.NotExisted");
            }
            else
            {
                material = await _materialQueries.GetByIdAsync(request.Model);

                if (material == null)
                {
                    throw new BusinessException("Account.NotExisted");
                }
                else if (material.PartnerId != company.Id)
                {
                    throw new BusinessException("Common.NoPermission");
                }
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        material.IsDeleted    = true;
                        material.ModifiedDate = DateTime.Now;
                        material.ModifiedBy   = request.LoginSession.Id;

                        if (await _materialRepository.UpdateAsync(material) > 0)
                        {
                            rs = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }
            return(rs);
        }
示例#18
0
        public override async Task <int> HandleCommand(DeleteProductionCommand request, CancellationToken cancellationToken)
        {
            Production production = null;

            if (request.Model == 0)
            {
                throw new BusinessException("Production.NotSelected");
            }
            else
            {
                production = await productionQueries.GetByIdAsync(request.Model);

                if (production == null)
                {
                    throw new BusinessException("Production.NotSelected");
                }
            }

            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null || production.PartnerId != company.Id)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        production.IsDeleted    = true;
                        production.ModifiedDate = DateTime.Now;
                        production.ModifiedBy   = request.LoginSession.Id;

                        if (await productionRepository.UpdateAsync(production) > 0)
                        {
                            rs = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }

            return(rs);
        }
        public override async Task <int> HandleCommand(InsertAccountPartnerCommand request, CancellationToken cancellationToken)
        {
            var company = await _companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var id = 0;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        request.Model.RoleId = (await _settingQueries.GetValueAsync(SettingKeys.Role_Default)).ToInt();
                        if ((await _roleQueries.GetByIdAsync(request.Model.RoleId ?? 0)) == null)
                        {
                            throw new BusinessException("Role.NotSelected");
                        }

                        request.Model.PartnerId        = company.Id;
                        request.Model.CreatedDate      = DateTime.Now;
                        request.Model.CreatedBy        = request.LoginSession.Id;
                        request.Model.ModifiedDate     = DateTime.Now;
                        request.Model.ModifiedBy       = request.LoginSession.Id;
                        request.Model.SecurityPassword = Guid.NewGuid();
                        request.Model.Password         = (request.Model.NewPassword + request.Model.SecurityPassword.ToString()).CalculateMD5Hash();

                        id = await _accountRepository.AddAsync((Account)request.Model);

                        if (id > 0)
                        {
                            await _accountRoleRepository.AddAsync(new AccountRole()
                            {
                                RoleId        = request.Model.RoleId ?? 0,
                                UserAccountId = id,
                                CreatedDate   = DateTime.Now,
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (id > 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }

            return(id);
        }