コード例 #1
0
ファイル: Detail.aspx.cs プロジェクト: robgray/Tucana
        protected void SaveAccount(object sender, EventArgs e)
        {
            Account account;
            if (IsMaster)
            {
                var master = new MasterAccount(Account.AccountId.Value);
                if (hdnCompanyId.Value.Length > 0)
                {
                    int id;
                    if (int.TryParse(hdnCompanyId.Value, out id))
                    {
                        if (id > 0) master.CompanyId = id;
                    }
                }
                account = master;
            }
            else
            {
                var sub = new SubAccount(Account.AccountId.Value);
                if (hdnMasterAccountId.Value.Length > 0)
                {
                    int id;
                    if (int.TryParse(hdnMasterAccountId.Value, out id))
                    {
                        if (id > 0) sub.MasterAccountId = id;
                    }
                }
                account = sub;
            }

            account.AccountName = Account.AccountName;
            account.AccountNumber = Account.AccountNumber;
            account.BillingAddressType = Account.BillingAddressType;
            account.BillingMethod = Account.BillingMethod;
            account.ContactRole = Account.ContactRole;
            account.EmailBill = Account.EmailBill;
            account.EmailBillDataFile = Account.EmailBillDataFile;
            account.Password = Account.Password;
            account.PostBill = Account.PostBill;
            account.IsInvoiceRoot = Account.IsInvoiceRoot;
            account.IsInternational = Account.IsInternational;
            account.AmountPaid = Account.AmountPaid;
            account.PreviousBill = Account.PreviousBill;

            if (hdnContactId.Value.Length > 0)
            {
                int contactId;
                if (int.TryParse(hdnContactId.Value, out contactId))
                {
                    if (contactId > 0) account.ContactId = contactId;
                }
            }

            var request = new SaveAccountRequest
            {
                Account = account,
                User = Users.Current
            };

            var response = AccountService.SaveAccount(request);
            if (response.IsSuccessful)
            {
                UserMessage.SetSuccess("Acount Saved");
            }
            else
            {
                UserMessage.SetFailure(response.Message);
            }
        }
コード例 #2
0
ファイル: New.aspx.cs プロジェクト: robgray/Tucana
        protected void SaveAccount(object sender, EventArgs e)
        {
            var sub = new SubAccount();
            sub.MasterAccountId = MasterAccountId;

            sub.AccountName = Account.AccountName;
            sub.BillingAddressType = Account.BillingAddressType;
            sub.BillingMethod = Account.BillingMethod;
            sub.ContactRole = Account.ContactRole;
            sub.EmailBill = Account.EmailBill;
            sub.EmailBillDataFile = Account.EmailBillDataFile;
            sub.Password = Account.Password;
            sub.PostBill = Account.PostBill;
            sub.IsInvoiceRoot = Account.IsInvoiceRoot;
            sub.IsInternational = Account.IsInternational;
            sub.AmountPaid = Account.AmountPaid;

            if (hdnContactId.Value.Length > 0)
            {
                int contactId;
                if (int.TryParse(hdnContactId.Value, out contactId))
                {
                    if (contactId > 0) sub.ContactId = contactId;
                }
            }

            var request = new SaveAccountRequest
            {
                Account = sub,
                User = Users.Current
            };

            var response = AccountService.SaveAccount(request);
            if (response.IsSuccessful)
            {
                UserMessage.SetSuccess("Acount Saved");
                SavedPanel.Visible = true;
                SavePanel.Visible = false;
            }
            else
            {
                LoggingUtility.LogDebug("SaveAccount", GetType().FullName, "Could not save new Sub Account: " + response.Message);
                UserMessage.SetFailure(response.Message);
                SavedPanel.Visible = false;
                SavePanel.Visible = true;
            }
        }
コード例 #3
0
ファイル: AccountService.cs プロジェクト: robgray/Tucana
        public SaveAccountResponse SaveAccount(SaveAccountRequest request)
        {
            var response = new SaveAccountResponse();

            #region Validation

            if (request.User == null || request.User is AgentUser || request.User is ContactUser)
            {
                response.IsSuccessful = false;
                response.Message = Constants.Messages.NO_PERMISSIONS;
                return response;
            }
            System.Threading.Thread.CurrentPrincipal = request.User.GetUserPrincipal();

            var contact = _contactRepository.GetContactEntity(request.Account.ContactId);
            if (contact == null)
            {
                response.Message = "A valid Contact must be given for this Account";
                return response;
            }

            if (request.Account.Id != null && string.IsNullOrEmpty(request.Account.AccountNumber))
            {
                response.Message = "An Account Number must be given for this Account";
                return response;
            }
            else if (request.Account.Id == null)
            {
                // get account number
                request.Account.AccountNumber = _generator.NextAccountNumber();
                if (string.IsNullOrEmpty(request.Account.AccountNumber))
                {
                    response.Message = "Failed to generate Account Number";
                    return response;
                }
            }

            if (string.IsNullOrEmpty(request.Account.Password))
            {
                response.Message = "A Passwod must be given for this Account";
                return response;
            }

            // Master Accounts Don't need to have Companies.
            //if (request.Account is MasterAccount)
            //{
            //    var master = (MasterAccount)request.Account;
            //    if (!master.CompanyId.HasValue)
            //    {
            //        response.Message = "A Company must be given for this Master Account";
            //        return response;
            //    }
            //    var company = _companyRepository.GetCompany(master.CompanyId.Value);
            //    if (company == null)
            //    {
            //        response.Message = "A valid Company must be given for this Master Account";
            //        return response;
            //    }
            //}

            if (request.Account is SubAccount)
            {
                var sub = (SubAccount)request.Account;
                if (sub.MasterAccountId == 0)
                {
                    response.Message = "This Sub Account must be associated with a parent Master Account";
                    return response;
                }
                else
                {
                    MasterAccount master = (MasterAccount)_accountRepository.GetAccount(sub.MasterAccountId);
                    if (master == null)
                    {
                        response.Message = "A valid Master Account must be given for this Account";
                        return response;
                    }
                }
            }

            // Cannot allow emailing of bill if no email provided on Account Contact
            if (string.IsNullOrEmpty(contact.Email) && (request.Account.EmailBill || request.Account.EmailBillDataFile))
            {
                response.Message = "A contact email must be supplied if recieving paperless bills";
                return response;
            }

            // IF SELECTING PAPERLESS INVOICING/BILLING, AN EMAIL ADDRESS MUST BE SUPPLIED
            if (request.Account.EmailBill && string.IsNullOrEmpty(contact.Email))
            {
                response.Message = "Please ensure an email address is supplied when requesting Invoices to be emailed";
                return response;
            }

            if (request.Account.EmailBillDataFile && string.IsNullOrEmpty(contact.Email))
            {
                response.Message = "Please ensure an email address is supplied when requesting Invoice data to be emailed";
                return response;
            }

            #endregion

            // Ensure HasRequestedInvoice is false.
            // Invoice Requesting is only valid when creating a new contract.
            request.Account.HasRequestedInvoicing = false;

            try
            {
                using (var ts = new TransactionScope())
                {
                    if (request.Account.Id == null)
                    {
                        _accountRepository.InsertAccount(request.Account);
                        if (request.Account.Id != null)
                        {
                            request.Account.LogActivity("New Account Addded");
                            response.IsSuccessful = true;
                            ts.Complete();
                        }
                        else
                        {
                            response.Message = Constants.Messages.INTERNAL_ERROR;
                        }
                    }
                    else
                    {
                        if (_accountRepository.UpdateAccount(request.Account))
                        {
                            request.Account.LogActivity("Account Updated");
                            response.IsSuccessful = true;
                            ts.Complete();
                        }
                        else
                        {
                            response.Message = Constants.Messages.INTERNAL_ERROR;
                        }
                    }
                }
            }
            catch (Exception)
            {
                // TODO: Log the exception
                response.Message = Constants.Messages.INTERNAL_ERROR;
                response.IsSuccessful = false;
            }

            return response;
        }