private Account Create(AccountCriteria criteria)
        {
            var item = (Account)Activator.CreateInstance(typeof(Account), true);

            bool cancel = false;
            OnCreating(ref cancel);
            if (cancel) return item;

            var resource = Fetch(criteria);
            using (BypassPropertyChecks(item))
            {
                item.Email = resource.Email;
                item.FirstName = resource.FirstName;
                item.LastName = resource.LastName;
                item.Address1 = resource.Address1;
                item.Address2 = resource.Address2;
                item.City = resource.City;
                item.State = resource.State;
                item.Zip = resource.Zip;
                item.Country = resource.Country;
                item.Phone = resource.Phone;
            }

            CheckRules(item);
            MarkNew(item);
            MarkAsChild(item);

            OnCreated();

            return item;
        }
        private void Child_Fetch(AccountCriteria criteria)
        {
            bool cancel = false;
            OnFetching(criteria, ref cancel);
            if (cancel) return;

            RaiseListChangedEvents = false;

            // Fetch Child objects.
            string commandText = String.Format("SELECT [AccountId], [UniqueID], [Email], [FirstName], [LastName], [Address1], [Address2], [City], [State], [Zip], [Country], [Phone] FROM [dbo].[Account] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                    using(var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if(reader.Read())
                        {
                            do
                            {
                                this.Add(PetShop.Business.Account.GetAccount(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            RaiseListChangedEvents = true;

            OnFetched();
        }
        /// <summary>
        /// Retrieves data from the data base into a CSLA editable child business object of type <see cref="Account"/> 
        /// using the criteria provided. 
        /// </summary>
        /// <param name="criteria">Object of type <see cref="AccountCriteria"/></param>
        /// <returns></returns>
        private void Child_Fetch(AccountCriteria criteria)
        {
            bool cancel = false;
            OnChildFetching(criteria, ref cancel);
            if (cancel) return;

            string commandText = String.Format("SELECT [AccountId], [UniqueID], [Email], [FirstName], [LastName], [Address1], [Address2], [City], [State], [Zip], [Country], [Phone] FROM [dbo].[Account] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    using(var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if(reader.Read())
                            Map(reader);
                        else
                            throw new Exception(String.Format("The record was not found in 'dbo.Account' using the following criteria: {0}.", criteria));
                    }
                }
            }

            OnChildFetched();

        }
Esempio n. 4
0
        public JsonResult Add(AccountCriteria criteria)
        {
            criteria.OptUserName = UserContext.Current.Name;
            var reg = iAuthorityMenuProvider.AddAccount(criteria);

            return(Json(new Ets.Model.Common.ResultModel(reg.DealFlag, reg.DealMsg), JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        /// <summary>
        /// This call to delete is for immediate deletion and doesn't keep track of any entity state.
        /// </summary>
        /// <param name="criteria">The Criteria.</param>
        private void DoDelete(AccountCriteria criteria)
        {
            bool cancel = false;

            OnDeleting(criteria, ref cancel);
            if (cancel)
            {
                return;
            }

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Account_Delete]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                    //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed.
                    int result = command.ExecuteNonQuery();
                    if (result == 0)
                    {
                        throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                    }
                }
            }

            OnDeleted();
        }
        /// <summary>
        /// Fetch AccountList.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public AccountList Fetch(AccountCriteria criteria)
        {
            AccountList item = (AccountList)Activator.CreateInstance(typeof(AccountList), true);

            bool cancel = false;
            OnFetching(criteria, ref cancel);
            if (cancel) return item;

            // Fetch Child objects.
            string commandText = String.Format("SELECT [AccountId], [UniqueID], [Email], [FirstName], [LastName], [Address1], [Address2], [City], [State], [Zip], [Country], [Phone] FROM [dbo].[Account] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    using(var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                item.Add(new AccountFactory().Map(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            MarkOld(item);
            MarkAsChild(item);
            OnFetched();
            return item;
        }
Esempio n. 7
0
        /// <summary>
        /// Fetch Account.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public Account Fetch(AccountCriteria criteria)
        {
            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(null);
            }

            Account item;

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Account_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_Address2HasValue", criteria.Address2HasValue);
                    command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue);
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            item = Map(reader);
                        }
                        else
                        {
                            throw new Exception(String.Format("The record was not found in 'dbo.Account' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }

            MarkOld(item);
            MarkAsChild(item);
            OnFetched();
            return(item);
        }
        /// <summary>
        /// Fetch AccountList.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public AccountList Fetch(AccountCriteria criteria)
        {
            AccountList item = (AccountList)Activator.CreateInstance(typeof(AccountList), true);

            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(item);
            }

            // Fetch Child objects.
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Account_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_Address2HasValue", criteria.Address2HasValue);
                    command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue);
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                item.Add(new AccountFactory().Map(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            MarkOld(item);
            MarkAsChild(item);
            OnFetched();
            return(item);
        }
        /// <summary>
        /// Fetch AccountList.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public AccountList Fetch(AccountCriteria criteria)
        {
            AccountList item = (AccountList)Activator.CreateInstance(typeof(AccountList), true);

            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(item);
            }

            // Fetch Child objects.
            string commandText = String.Format("SELECT [AccountId], [UniqueID], [Email], [FirstName], [LastName], [Address1], [Address2], [City], [State], [Zip], [Country], [Phone] FROM [dbo].[Account] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                item.Add(new AccountFactory().Map(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            MarkOld(item);
            MarkAsChild(item);
            OnFetched();
            return(item);
        }
Esempio n. 10
0
        protected void DoDelete(ref Account item)
        {
            // If we're not dirty then don't update the database.
            if (!item.IsDirty)
            {
                return;
            }

            // If we're new then don't call delete.
            if (item.IsNew)
            {
                return;
            }

            var criteria = new AccountCriteria {
                AccountId = item.AccountId
            };

            DoDelete(criteria);

            MarkNew(item);
        }
        /// <summary>
        /// Fetch Account.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public Account Fetch(AccountCriteria criteria)
        {
            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(null);
            }

            Account item;
            string  commandText = String.Format("SELECT [AccountId], [UniqueID], [Email], [FirstName], [LastName], [Address1], [Address2], [City], [State], [Zip], [Country], [Phone] FROM [dbo].[Account] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            item = Map(reader);
                        }
                        else
                        {
                            throw new Exception(String.Format("The record was not found in 'dbo.Account' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }

            MarkOld(item);
            MarkAsChild(item);
            OnFetched();
            return(item);
        }
Esempio n. 12
0
        private Account Create(AccountCriteria criteria)
        {
            var item = (Account)Activator.CreateInstance(typeof(Account), true);

            bool cancel = false;

            OnCreating(ref cancel);
            if (cancel)
            {
                return(item);
            }

            var resource = Fetch(criteria);

            using (BypassPropertyChecks(item))
            {
                item.Email     = resource.Email;
                item.FirstName = resource.FirstName;
                item.LastName  = resource.LastName;
                item.Address1  = resource.Address1;
                item.Address2  = resource.Address2;
                item.City      = resource.City;
                item.State     = resource.State;
                item.Zip       = resource.Zip;
                item.Country   = resource.Country;
                item.Phone     = resource.Phone;
            }

            CheckRules(item);
            MarkNew(item);
            MarkAsChild(item);

            OnCreated();

            return(item);
        }
        /// <summary>
        /// Fetch AccountList.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public AccountList Fetch(AccountCriteria criteria)
        {
            AccountList item = (AccountList)Activator.CreateInstance(typeof(AccountList), true);

            bool cancel = false;
            OnFetching(criteria, ref cancel);
            if (cancel) return item;

            // Fetch Child objects.
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Account_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_Address2HasValue", criteria.Address2HasValue);
                command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue);
                    using(var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if(reader.Read())
                        {
                            do
                            {
                                item.Add(new AccountFactory().Map(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            MarkOld(item);
            MarkAsChild(item);
            OnFetched();
            return item;
        }
Esempio n. 14
0
        /// <summary>
        /// 添加用户
        /// danny-20150323
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public DealResultInfo AddAccount(AccountCriteria criteria)
        {
            var dealResultInfo = new DealResultInfo
            {
                DealFlag = false
            };
            var accountModel = new account
            {
                Id          = criteria.Id,
                UserName    = criteria.UserName,
                LoginName   = criteria.LoginName,
                Password    = string.IsNullOrWhiteSpace(criteria.Password)?"":MD5Helper.MD5(criteria.Password),
                GroupId     = criteria.GroupId,
                Status      = criteria.Status,
                AccountType = criteria.AccountType
            };
            var isHave = authoritySetDao.CheckHasAccountName(accountModel);

            if (criteria.OptionType == "0")//添加用户
            {
                if (isHave)
                {
                    dealResultInfo.DealMsg = "用户名已存在!";
                    return(dealResultInfo);
                }
            }
            else//修改用户信息
            {
                if (!isHave)
                {
                    dealResultInfo.DealMsg = "此用户不存在!";
                    return(dealResultInfo);
                }
            }
            using (var tran = EdsUtilOfWorkFactory.GetUnitOfWorkOfEDS())
            {
                var accountCityRelation = new AccountCityRelation
                {
                    AccountId = criteria.Id,
                    CreateBy  = criteria.OptUserName,
                    UpdateBy  = criteria.OptUserName,
                };
                if (criteria.OptionType == "0")//添加用户
                {
                    accountCityRelation.AccountId = authoritySetDao.AddAccount(accountModel);
                    if (accountCityRelation.AccountId == 0)
                    {
                        dealResultInfo.DealMsg = "插入用户信息失败!";
                        return(dealResultInfo);
                    }
                }
                else//修改用户信息
                {
                    if (!authoritySetDao.ModifyAccount(accountModel))
                    {
                        dealResultInfo.DealMsg = "修改用户信息失败!";
                        return(dealResultInfo);
                    }
                }
                if (!string.IsNullOrWhiteSpace(criteria.CityCodeList))
                {
                    var cityCodeList = criteria.CityCodeList.Split(',');

                    authoritySetDao.DeleteAccountCityRelation(accountCityRelation);
                    foreach (var cityCode in cityCodeList)
                    {
                        accountCityRelation.CityId = ParseHelper.ToInt(cityCode);
                        if (!authoritySetDao.AddAccountCityRelation(accountCityRelation))
                        {
                            dealResultInfo.DealMsg = "插入用户和城市关联信息失败!";
                            return(dealResultInfo);
                        }
                    }
                }
                tran.Complete();
            }
            dealResultInfo.DealMsg  = "用户信息提交成功!";
            dealResultInfo.DealFlag = true;
            return(dealResultInfo);
        }
Esempio n. 15
0
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="Account"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="AccountCriteria"/> object containing the criteria of the object to delete.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param>
 partial void OnDeleting(AccountCriteria criteria, ref bool cancel);
Esempio n. 16
0
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the <see cref="Account"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="AccountCriteria"/> object containing the criteria of the object to fetch.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param>
 partial void OnFetching(AccountCriteria criteria, ref bool cancel);
        /// <summary>
        /// Deletes data in the data base using the criteria specified in the AccountCriteria object.
        /// </summary>
        /// <param name="criteria">Object of type <see cref="AccountCriteria"/></param>
        /// <returns></returns>
        protected void DataPortal_Delete(AccountCriteria criteria, SqlConnection connection)
        {
            bool cancel = false;
            OnDeleting(criteria, connection, ref cancel);
            if (cancel) return;

            var commandText = String.Format("DELETE FROM [dbo].[Account] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));
            using (var command = new SqlCommand(commandText, connection))
            {
                command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. 
                int result = command.ExecuteNonQuery();
                if (result == 0)
                    throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
            }

            OnDeleted();
        }
 public void Delete(AccountCriteria criteria)
 {
     //Note: this call to delete is for immediate deletion and doesn't keep track of any entity state.
     DoDelete(criteria);
 }
Esempio n. 19
0
 public void Delete(AccountCriteria criteria)
 {
     //Note: this call to delete is for immediate deletion and doesn't keep track of any entity state.
     DoDelete(criteria);
 }
        protected void DoDelete(ref Account item)
        {
            // If we're not dirty then don't update the database.
            if (!item.IsDirty) return;

            // If we're new then don't call delete.
            if (item.IsNew) return;
            
            var criteria = new AccountCriteria{AccountId = item.AccountId};
            
            DoDelete(criteria);

            MarkNew(item);
        }
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the child <see cref="Account"/> object. 
 /// </summary>
 /// <param name="criteria"><see cref="AccountCriteria"/> object containing the criteria of the object to fetch.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param>
 partial void OnFetching(AccountCriteria criteria, ref bool cancel);
        /// <summary>
        /// This call to delete is for immediate deletion and doesn't keep track of any entity state.
        /// </summary>
        /// <param name="criteria">The Criteria.</param>
        private void DoDelete(AccountCriteria criteria)
        {
            bool cancel = false;
            OnDeleting(criteria, ref cancel);
            if (cancel) return;

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Account_Delete]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                    //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. 
                    int result = command.ExecuteNonQuery();
                    if (result == 0)
                        throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                }
            }

            OnDeleted();
        }
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="Account"/> object. 
 /// </summary>
 /// <param name="criteria"><see cref="AccountCriteria"/> object containing the criteria of the object to delete.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param>
 partial void OnDeleting(AccountCriteria criteria, ref bool cancel);
        /// <summary>
        /// Fetch Account.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public Account Fetch(AccountCriteria criteria)
        {
            bool cancel = false;
            OnFetching(criteria, ref cancel);
            if (cancel) return null;

            Account item;
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Account_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_Address2HasValue", criteria.Address2HasValue);
                command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue);
                    using(var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if(reader.Read())
                           item = Map(reader);
                        else
                            throw new Exception(String.Format("The record was not found in 'dbo.Account' using the following criteria: {0}.", criteria));
                    }
                }
            }

            MarkOld(item);
            MarkAsChild(item);
            OnFetched();
            return item;
        }