示例#1
0
        public ResponseBase <List <CustomerContract> > ReadCustomers()
        {
            var response = new ResponseBase <List <CustomerContract> >();
            var list     = new List <CustomerContract>();

            try
            {
                using (var context = new EF_DataBaseEntities())
                {
                    var result = context.USP_CUSTOMER_READ(0, null);

                    foreach (var item in result)
                    {
                        var customer = new CustomerContract()
                        {
                            Name             = item.Name,
                            Address          = item.Address,
                            BirthDate        = item.BirthDate.ToDateString(),
                            Id               = item.CustomerId,
                            DocumentId       = item.DocumentId,
                            DocumentType     = item.DocumentType,
                            DocumentTypeName = item.DocumentTypeName,
                            CityId           = item.CityId,
                            CityName         = item.CityName,
                            DepartmentName   = item.DepartmentName,
                            CountryName      = item.CountryName,
                            DepartmentId     = item.DepartmentId,
                            CountryId        = item.CountryId
                        };
                        list.Add(customer);
                    }

                    response.Code = StatusCode.Ok;
                    response.Data = list;
                }
            }
            catch (Exception ex)
            {
                response.Code    = StatusCode.InternalError;
                response.Message = ex.Message;
            }

            return(response);
        }
示例#2
0
        public ResponseBase <CustomerContract> ReadCustomerByIdOrName(long id = 0, string name = "")
        {
            var response = new ResponseBase <CustomerContract>();
            var customer = new CustomerContract();

            try
            {
                using (var context = new EF_DataBaseEntities())
                {
                    var result = context.USP_CUSTOMER_READ(id, !string.IsNullOrWhiteSpace(name) ? name : null);

                    foreach (var item in result)
                    {
                        customer.Name             = item.Name;
                        customer.Address          = item.Address;
                        customer.BirthDate        = item.BirthDate.ToDateString();
                        customer.Id               = item.CustomerId;
                        customer.DocumentId       = item.DocumentId;
                        customer.DocumentType     = item.DocumentType;
                        customer.DocumentTypeName = item.DocumentTypeName;
                        customer.CityId           = item.CityId;
                        customer.CityName         = item.CityName;
                        customer.DepartmentName   = item.DepartmentName;
                        customer.CountryName      = item.CountryName;
                        customer.DepartmentId     = item.DepartmentId;
                        customer.CountryId        = item.CountryId;
                    }

                    response.Code = StatusCode.Ok;
                    response.Data = customer;
                }
            }
            catch (Exception ex)
            {
                response.Code    = StatusCode.InternalError;
                response.Message = ex.Message;
            }

            return(response);
        }