Пример #1
0
        public int CreateCompanyConsignee(CompanyConsigneeBindingModel companyConsigneeModel)
        {
            int?createdConsigneeId = null;
            var companyCosignee    = new CompanyConsignee();

            companyCosignee.CompanyName    = companyConsigneeModel.CompanyName;
            companyCosignee.CompanyTRN     = companyConsigneeModel.CompanyTRN;
            companyCosignee.CompanyAddress = companyConsigneeModel.CompanyAddress;
            companyCosignee.CompanyEmail   = companyConsigneeModel.CompanyEmail;
            companyCosignee.CompanyPhone   = companyCosignee.CompanyPhone;
            companyCosignee.CustomerCode   = companyCosignee.CustomerCode;

            using (var sqlConnection = new SqlConnection(_DBConnectionString))
            {
                try
                {
                    sqlConnection.Open();
                    createdConsigneeId = sqlConnection.ExecuteScalar <int>(
                        @"INSERT INTO CompanyConsignee (CompanyName,CompanyTRN,CompanyAddress,CompanyEmail,CompanyPhoneNumber,CustomerCode) 
                        OUTPUT Inserted.Id Values (@companyConsignee)", companyCosignee,
                        commandType: CommandType.Text, commandTimeout: 60);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    //log exceptions here
                }
            }
            return(createdConsigneeId.Value);
        }
        public int?CreateCompanyConsignee(CompanyConsigneeBindingModel companyConsigneeModel)
        {
            int?createdConsigneeId = null;
            var CompanyCosignee    = new CompanyConsignee();

            using (var sqlConnection = new SqlConnection(_DBConnectionString))
            {
                try
                {
                    //TODO replace with stored procedures
                    sqlConnection.Open();
                    createdConsigneeId = sqlConnection.ExecuteScalar <int>(
                        @"INSERT INTO CompanyConsignee (CompanyName,CompanyTRN,CompanyAddress,CompanyEmail,CompanyPhoneNumber)
                        OUTPUT Inserted.Id Values (@CompanyName,@CompanyTRN,@CompanyAddress,@CompanyEmail,@CompanyPhone)",
                        new
                    {
                        CompanyName    = companyConsigneeModel.CompanyName,
                        CompanyTRN     = companyConsigneeModel.CompanyTRN,
                        CompanyAddress = companyConsigneeModel.CompanyAddress,
                        CompanyEmail   = companyConsigneeModel.CompanyEmail,
                        CompanyPhone   = CompanyCosignee.CompanyPhone,
                    },
                        commandType: CommandType.Text, commandTimeout: 60);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Error creating company consignee.");

                    //TODO - Rethrow exception here
                    //ex.ToString();
                    //log exceptions here
                }
            }
            return(createdConsigneeId);
        }
        public int CreateCompanyConsignee(CompanyConsigneeBindingModel companyConsigneeModel)
        {
            int? createdConsigneeId = null; 
            var companyCosignee = new CompanyConsignee();

            companyCosignee.CompanyName = companyConsigneeModel.CompanyName;
            companyCosignee.CompanyTRN = companyConsigneeModel.CompanyTRN;
            companyCosignee.CompanyAddress = companyConsigneeModel.CompanyAddress;
            companyCosignee.CompanyEmail = companyConsigneeModel.CompanyEmail;
            companyCosignee.CompanyPhone = companyCosignee.CompanyPhone;
            companyCosignee.CustomerCode = companyCosignee.CustomerCode;
            
            using (var sqlConnection = new SqlConnection(_DBConnectionString))
            {
                try
                {
                    sqlConnection.Open();
                    createdConsigneeId = sqlConnection.ExecuteScalar<int>(
                       @"INSERT INTO CompanyConsignee (CompanyName,CompanyTRN,CompanyAddress,CompanyEmail,CompanyPhoneNumber,CustomerCode) 
                        OUTPUT Inserted.Id Values (@companyConsignee)",companyCosignee, 
                      commandType: CommandType.Text, commandTimeout: 60);

                }
                catch (Exception ex)
                {
                    ex.ToString();
                    //log exceptions here

                }
            }
            return createdConsigneeId.Value;
        }
Пример #4
0
        public GenericActionResult <RegistrationReturnModel <CompanyConsigneeBindingModel> > RegisterCompanyWithPrincipal(CreateUserBindingModel principalUser, CompanyConsigneeBindingModel companyConsignee)
        {
            bool companyAlreadyExists = _validationHelper.CheckForExistingCompany(companyConsignee.CompanyTRN);

            if (companyAlreadyExists)
            {
                return(new GenericActionResult <RegistrationReturnModel <CompanyConsigneeBindingModel> >()
                {
                    IsSuccess = false,
                    Errors = new List <string> {
                        "Company already registered, duplicate TRN"
                    }
                });
            }

            var createUserResult = _userManagement.CreateUser(principalUser);

            string userId = null;

            if (createUserResult.IsSuccess)
            {
                userId = createUserResult.Result.Id;

                AssignUserToDefaultRoles(userId);
            }
            else
            {
                return new GenericActionResult <RegistrationReturnModel <CompanyConsigneeBindingModel> >()
                       {
                           IsSuccess = false, Errors = createUserResult.Errors
                       }
            };

            //create and get company id to create a link between created user
            int?companyId = _dataAccess.CreateCompanyConsignee(companyConsignee);

            //if no company Id was returned, it means an error occured during creation of the user
            //in that case roll back the created user transactions
            if (!companyId.HasValue)
            {
                //TODO could use transactions here
                //reverse the created user by deleting it
                _userManagement.DeleteUser(createUserResult.Result.UserName);

                return(new GenericActionResult <RegistrationReturnModel <CompanyConsigneeBindingModel> >()
                {
                    IsSuccess = false,
                    Errors = new List <string> {
                        "Error completing registration,please try again later."
                    }
                });
            }

            //create a link record between the company and the user
            _dataAccess.CreateCompanyConsigneeRepresentative(userId, companyId.Value);

            //return new information on user & company
            return(new GenericActionResult <RegistrationReturnModel <CompanyConsigneeBindingModel> >()
            {
                IsSuccess = true,
                Errors = null,
                Result = new RegistrationReturnModel <CompanyConsigneeBindingModel>()
                {
                    UserModel = createUserResult.Result,
                    ConsigneeModel = companyConsignee
                }
            });
        }
 public int CreateConsignee(CompanyConsigneeBindingModel companyConsigneeModel)
 {
     throw new NotImplementedException();
 }