Пример #1
0
        public int Execution(UpdateCustomerAddressRequest input)
        {
            var entity = input.Payload.GetEntity();

            bool primaryUpdated = false, postaddressUpdated = false;

            if (entity.IsPrimary.HasValue)
            {
                _updateCustomerAddressPrimary.BuildQuery(new UpdateCustomerAddressIsPrimary
                {
                    CustomerId     = input.CustomerId,
                    OrganizationId = input.OrganizationId,
                    IsPrimary      = entity.IsPrimary.Value,
                    AddressId      = input.Id
                });

                postaddressUpdated = _commandExecutor.ExecuteNonQuery(_updateCustomerAddressPrimary) > 0;
            }

            if (entity.IsPostAddress.HasValue)
            {
                _updateCustomerAddressPost.BuildQuery(new UpdateCustomerAddressIsPostAddress
                {
                    CustomerId     = input.CustomerId,
                    OrganizationId = input.OrganizationId,
                    AddressId      = input.Id,
                    IsPostAddress  = entity.IsPostAddress.Value
                });

                primaryUpdated = _commandExecutor.ExecuteNonQuery(_updateCustomerAddressPost) > 0;
            }

            return((primaryUpdated || postaddressUpdated) ? 1 : 0);
        }
 public override int ExecuteNonQuery()
 {
     try
     {
         executionContext = Prepare(CommandText);
         return(_commandExecutor.ExecuteNonQuery(true, executionContext).Sum());
     }
     finally
     {
         currentResultSet = null;
     }
 }
        private int Delete(BulkDeleteCostItemsRequest input)
        {
            var param = new BulkDeleteCostItems
            {
                OrganizationId = input.OrganizationId,
                CostItems      = input.CostItems
            };

            _deleteCommand.BuildQuery(param);

            return(_deleteExecutor.ExecuteNonQuery(_deleteCommand));
        }
        private int Delete(OrganizationEntityRequest input)
        {
            var param = new ToggleIsDelete
            {
                Id             = input.Id,
                IsDelete       = true,
                OrganizationId = input.OrganizationId
            };

            _deleteCommand.BuildQuery(param);

            return(_deleteExecutor.ExecuteNonQuery(_deleteCommand));
        }
Пример #5
0
        private int Delete(DeleteJobStaffRequest input)
        {
            var param = new DeleteJobStaff
            {
                JobId          = input.JobId,
                StaffId        = input.StaffId,
                OrganizationId = input.OrganizationId
            };

            _deleteCommand.BuildQuery(param);

            return(_deleteExecutor.ExecuteNonQuery(_deleteCommand));
        }
        public int Execution(UpdateCustomerContactRequest input)
        {
            var entity = input.Payload.GetEntity();

            if (!entity.IsPrimary.HasValue)
            {
                return(0);
            }

            _updateCustomerContactPrimary.BuildQuery(new UpdateCustomerContactIsPrimary
            {
                CustomerId     = input.CustomerId,
                OrganizationId = input.OrganizationId,
                IsPrimary      = entity.IsPrimary.Value,
                ContactId      = input.ContactId
            });

            return(_commandExecutor.ExecuteNonQuery(_updateCustomerContactPrimary));
        }
 public override int ExecuteNonQuery()
 {
     return(_commandExecutor.ExecuteNonQuery(this));
 }
        private int ProcessDeFacto(CreateStaffRequest input)
        {
            //check staff with the same login exists or not
            _getStaffByLogin.BuildQuery(new GetStaffByLoginEmail
            {
                Email          = input.Payload.Email,
                OrganizationId = input.OrganizationId
            });

            var alreadyCreatedStaff = _queryRunner.Run(_getStaffByLogin);

            if (alreadyCreatedStaff != null)
            {
                if (!alreadyCreatedStaff.IsDeleted)
                {
                    return(0);
                }

                //undelete
                _undeleteStaffCommand.BuildQuery(new UndeleteStaffByLoginEmail
                {
                    OrganizationId = input.OrganizationId,
                    LoginEmail     = input.Payload.Email
                });

                var resultCount = _executor.ExecuteNonQuery(_undeleteStaffCommand);

                _getStaffQuery.BuildQuery(new GetStaff
                {
                    OrganizationId = input.OrganizationId,
                    Id             = alreadyCreatedStaff.Id
                });

                var staff = _queryRunner.Run(_getStaffQuery);

                //reset privileges to default
                AdjustPrivileges(input.OrganizationId, staff.OrganizationUserId);

                return((resultCount > 0) ? alreadyCreatedStaff.Id : 0);
            }

            //TODO: password provider
            //if not exists, will create one, otherwise use the existing one
            _createCredential.BuildQuery(new CreateCredential
            {
                Email    = input.Payload.Email,
                Password = "******"
            });

            var credentialId = _executor.Execute(_createCredential);

            _createOrganizationUser.BuildQuery(new CreateOrganizationUser
            {
                OrganizationId         = input.OrganizationId,
                CredentialId           = credentialId,
                OrganizationUserTypeId = input.Payload.IsAdmin
                    ? (int)OrganizationUserTypes.Admin
                    : (int)OrganizationUserTypes.Staff
            });

            var orgUserId = _executor.Execute(_createOrganizationUser);

            _createStaffCommand.BuildQuery(new CreateStaff
            {
                OrganizationId = input.OrganizationId,
            });

            _createStaffCommand.BuildQuery(new CreateStaff
            {
                OrganizationId     = input.OrganizationId,
                Code               = input.Payload.Code,
                BaseRate           = input.Payload.BaseRate,
                BillableRate       = input.Payload.BillableRate,
                ContactEmail       = input.Payload.ContactEmail,
                Dob                = input.Payload.Dob,
                FirstName          = input.Payload.FirstName,
                Gender             = input.Payload.Gender,
                LastName           = input.Payload.LastName,
                MobilePhone        = input.Payload.MobilePhone,
                OrganizationUserId = orgUserId,
                OtherName          = input.Payload.OtherName
            });

            var staffId = _executor.Execute(_createStaffCommand);

            AdjustPrivileges(input.OrganizationId, orgUserId);

            return(staffId);
        }