Ejemplo n.º 1
0
 public CustomerAddressDTO GetCustomerAddressById(int id)
 {
     using (var db = new Context())
     {
         var address = db.CustomerAddress.FirstOrDefault(c => c.Id == id);
         return(CustomerAddressDTO.FromCustomerAddress(address));
     }
 }
Ejemplo n.º 2
0
 private bool ValidateAddress(CustomerAddressDTO addressDto)
 {
     if (string.IsNullOrEmpty(addressDto.Address1) ||
         string.IsNullOrEmpty(addressDto.Postcode))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
        public ActionResult AddAddress()
        {
            var newAddress = new CustomerAddressDTO()
            {
                CustomerId = Identity.LoggedInUserId
            };

            return(View("AddAddress", newAddress));
        }
Ejemplo n.º 4
0
        public void Save(CustomerAddressDTO address)
        {
            using (var db = new Context())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    var addressToSave = CustomerAddress.FromDto(address);
                    db.CustomerAddress.AddOrUpdate(addressToSave);

                    db.SaveChanges();
                    transaction.Commit();
                }
            }
        }
Ejemplo n.º 5
0
        public ActionResult SaveAddress(CustomerAddressDTO address)
        {
            if (!ValidateAddress(address))
            {
                if (address.Id > 0)
                {
                    return(View("EditAddress", address));
                }
                else
                {
                    return(View("AddAddress", address));
                }
            }
            _saveCustomerAddress.Save(address);
            var customer = CustomerDTO.FromCustomer(_getCustomer.GetById(address.CustomerId));

            return(View("ManageAccount", customer));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 提供下单选择客户的数据
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="groupId">分组Id</param>
        /// <returns>返回数据</returns>
        public List <CustomerForOrderDTO> GetCustomerListForOrder(string name, string groupId)
        {
            List <string>      conditions = new List <string>();
            List <DbParameter> parameters = new List <DbParameter>();
            DbParameter        parameter  = null;

            if (!string.IsNullOrEmpty(name))
            {
                conditions.Add("A.[Name] LIKE @Name");
                parameter       = DbHelper.CreateParameter("Name", DbType.String, 50);
                parameter.Value = "%" + name + "%";
                parameters.Add(parameter);
            }
            if (!string.IsNullOrEmpty(groupId))
            {
                conditions.Add("A.[GroupId] = @GroupId");
                parameter       = DbHelper.CreateParameter("GroupId", DbType.String, 32);
                parameter.Value = groupId;
                parameters.Add(parameter);
            }
            string whereCmdText = string.Empty;

            if (conditions.Count > 0)
            {
                whereCmdText = string.Format("WHERE {0}", string.Join(" AND ", conditions.ToArray()));
            }
            string       cmdText = string.Format("SELECT A.[Id], A.[Name], A.[Nickname], A.[Mobile], A.[GroupId], B.[Id] AddressId, B.[Address], B.[Linkman], B.[Mobile] LinkmanMobile, B.[IsDefault] FROM [dbo].[Customer] A JOIN [dbo].[CustomerAddress] B ON A.[Id] = B.[CustomerId] {0} ORDER BY A.[Name] ASC, B.[IsDefault] DESC", whereCmdText);
            DbDataReader reader  = DbHelper.ExecuteReader(cmdText, parameters.ToArray());

            List <CustomerForOrderDTO> entities = new List <CustomerForOrderDTO>();
            int    index  = -1;
            string lastId = string.Empty;

            while (reader.Read())
            {
                string             id         = reader["Id"].ToString();
                CustomerAddressDTO addressDto = new CustomerAddressDTO
                {
                    Id        = reader["AddressId"].ToString(),
                    Address   = reader["Address"].ToString(),
                    Linkman   = reader["Linkman"].ToString(),
                    Mobile    = reader["LinkmanMobile"].ToString(),
                    IsDefault = reader["IsDefault"].ToString()
                };
                if (id == lastId)
                {
                    entities[index].CustomerAddressList.Add(addressDto);
                }
                else
                {
                    CustomerForOrderDTO dto = new CustomerForOrderDTO
                    {
                        Id                  = id,
                        Name                = reader["Name"].ToString(),
                        Nickname            = reader["Nickname"].ToString(),
                        Mobile              = reader["Mobile"].ToString(),
                        GroupId             = reader["GroupId"].ToString(),
                        CustomerAddressList = new List <CustomerAddressDTO>()
                    };
                    dto.CustomerAddressList.Add(addressDto);
                    entities.Add(dto);
                    index++;
                    lastId = id;
                }
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return(entities);
        }
Ejemplo n.º 7
0
 public static CustomerAddress FromDto(CustomerAddressDTO dto)
 {
     return(new CustomerAddress(dto.Id, dto.CustomerId,
                                dto.Address1, dto.Address2, dto.Address3, dto.Address4, dto.Postcode));
 }