Ejemplo n.º 1
0
        public static int Create(AddressDataModel data, RequestProfile requestProfile)
        {
            var sql   = Save(data, "Create", requestProfile);
            var newId = DBDML.RunScalarSQL("Address.Insert", sql, DataStoreKey);

            return(Convert.ToInt32(newId));
        }
Ejemplo n.º 2
0
        public static string Save(AddressDataModel data, string action, RequestProfile requestProfile)
        {
            var sql = "EXEC ";


            switch (action)
            {
            case "Create":
                sql += "dbo.AddressInsert  " +
                       " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId) +
                       ", " + ToSQLParameter(BaseDataModel.BaseDataColumns.ApplicationId, requestProfile.ApplicationId);
                break;

            case "Update":
                sql += "dbo.AddressUpdate  " +
                       " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId);
                break;

            default:
                break;
            }
            sql = sql + ", " + ToSQLParameter(data, AddressDataModel.DataColumns.AddressId);
            sql = sql + ", " + ToSQLParameter(data, AddressDataModel.DataColumns.CityId);
            sql = sql + ", " + ToSQLParameter(data, AddressDataModel.DataColumns.StateId);
            sql = sql + ", " + ToSQLParameter(data, AddressDataModel.DataColumns.CountryId);
            sql = sql + ", " + ToSQLParameter(data, AddressDataModel.DataColumns.Address1);
            sql = sql + ", " + ToSQLParameter(data, AddressDataModel.DataColumns.Address2);
            sql = sql + ", " + ToSQLParameter(data, AddressDataModel.DataColumns.PostalCode);

            return(sql);
        }
Ejemplo n.º 3
0
        public static List <AddressDataModel> GetEntityDetails(AddressDataModel dataQuery, RequestProfile requestProfile, int returnAuditInfo = BaseDataManager.ReturnAuditInfoOnDetails)
        {
            const string sql = @"dbo.AddressSearch ";

            var parameters =
                new
            {
                AuditId           = requestProfile.AuditId
                , ApplicationId   = requestProfile.ApplicationId
                , ReturnAuditInfo = returnAuditInfo
                , AddressId       = dataQuery.AddressId
                , CityId          = dataQuery.CityId
                , StateId         = dataQuery.StateId
                , CountryId       = dataQuery.CountryId
            };

            List <AddressDataModel> result;

            using (var dataAccess = new DataAccessBase(DataStoreKey))
            {
                result = dataAccess.Connection.Query <AddressDataModel>(sql, parameters, commandType: CommandType.StoredProcedure).ToList();
            }

            return(result);
        }
Ejemplo n.º 4
0
        public static bool DoesExist(AddressDataModel data, RequestProfile requestProfile)
        {
            var doesExistRequest = new AddressDataModel();

            doesExistRequest.ApplicationId = data.ApplicationId;
            doesExistRequest.CityId        = data.CityId;
            doesExistRequest.StateId       = data.StateId;
            doesExistRequest.CountryId     = data.CountryId;

            var list = GetEntityDetails(doesExistRequest, requestProfile, 0);

            return(list.Count > 0);
        }
Ejemplo n.º 5
0
        public static void Delete(AddressDataModel data, RequestProfile requestProfile)
        {
            const string sql = @"dbo.AddressDelete ";

            var parameters =
                new
            {
                AuditId     = requestProfile.AuditId
                , AddressId = data.AddressId
            };

            using (var dataAccess = new DataAccessBase(DataStoreKey))
            {
                dataAccess.Connection.Execute(sql, parameters, commandType: CommandType.StoredProcedure);
            }
        }
Ejemplo n.º 6
0
        public static AddressDTO ToDTO(AddressDataModel datamodel)
        {
            AddressDTO dto = new AddressDTO();

            if (datamodel != null)
            {
                dto.AddressID     = datamodel.AddressID;
                dto.Title         = datamodel.Title;
                dto.Line1         = datamodel.Line1;
                dto.Line2         = datamodel.Line2;
                dto.Line3         = datamodel.Line3;
                dto.City          = datamodel.City;
                dto.State         = datamodel.State;
                dto.ZipCode       = datamodel.ZipCode;
                dto.AddressTypeID = datamodel.AddressTypeID;
            }

            return(dto);
        }
        public static AddressDTO ToDTO(AddressDataModel datamodel)
        {
            AddressDTO dto = new AddressDTO();

            if (datamodel != null)
            {
                dto.AddressID = datamodel.AddressID;
                dto.Title = datamodel.Title;
                dto.Line1 = datamodel.Line1;
                dto.Line2 = datamodel.Line2;
                dto.Line3 = datamodel.Line3;
                dto.City = datamodel.City;
                dto.State = datamodel.State;
                dto.ZipCode = datamodel.ZipCode;
                dto.AddressTypeID = datamodel.AddressTypeID;
            }

            return dto;
        }
Ejemplo n.º 8
0
        public virtual async Task <object> UpdateAddress(object userId, object modelId, IAddress address)
        {
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (modelId == null)
            {
                throw new ArgumentNullException(nameof(modelId));
            }

            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            var dataModel = new AddressDataModel
            {
                Id            = address.Id,
                AddressString = address.AddressString,
                CityId        = address.CityId,
                CountryId     = address.CountryId
            };

            await this.repository.UpdateAddress(modelId, dataModel);

            var now  = this.datetimeProvider.Now;
            var user = userId.ToString();

            await this.repository.Update(
                modelId,
                ExpressionBuilder <TDataModel>
                .UpdateExpression
                .Set(p => p.ModifiedByUser, user)
                .Set(p => p.DateModified, now));

            await this.repository.SaveChangesAsync();

            return(dataModel.Id);
        }
        public static AddressDataModel ToDataModel(AddressDTO dto)
        {

            AddressDataModel datamodel = new AddressDataModel();

            if (dto != null)
            {
                datamodel.AddressID = dto.AddressID;
                datamodel.Title = dto.Title;
                datamodel.Line1 = dto.Line1;
                datamodel.Line2 = dto.Line2;
                datamodel.Line3 = dto.Line3;
                datamodel.City = dto.City;
                datamodel.State = dto.State;
                datamodel.ZipCode = dto.ZipCode;
                datamodel.AddressTypeID = dto.AddressTypeID;
            }
            if (dto.Country != null)
            {
                CountryDTO countrydto = dto.Country;
                datamodel.CountryID = countrydto.CountryID;
                datamodel.AddressCountryAbbreviation = countrydto.Abbreviation;
                datamodel.AddressCountryCode = countrydto.Code;
                datamodel.AddressCountryName = countrydto.Name;
                datamodel.AddressCountryPhoneCode = countrydto.PhoneCode;
            }

            if (dto.TypeCode != null)
            {
                TypeCodeDTO typecodedto = dto.TypeCode;
                datamodel.AddressTypeID = typecodedto.TypeCodeID;
                datamodel.AddressTypeCode = typecodedto.Code;
                datamodel.AddressTypeCodeClassTypeID = typecodedto.ClassTypeID;
                datamodel.AddressTypeCodeDescription = typecodedto.Description;
                datamodel.AddressTypeCodeName = typecodedto.Name;
                datamodel.AddressTypeCodeParentTypeCodeID = typecodedto.ParentTypeCodeID;
            }

            return datamodel;
        }
Ejemplo n.º 10
0
        public static AddressDataModel ToDataModel(AddressDTO dto)
        {
            AddressDataModel datamodel = new AddressDataModel();

            if (dto != null)
            {
                datamodel.AddressID     = dto.AddressID;
                datamodel.Title         = dto.Title;
                datamodel.Line1         = dto.Line1;
                datamodel.Line2         = dto.Line2;
                datamodel.Line3         = dto.Line3;
                datamodel.City          = dto.City;
                datamodel.State         = dto.State;
                datamodel.ZipCode       = dto.ZipCode;
                datamodel.AddressTypeID = dto.AddressTypeID;
            }
            if (dto.Country != null)
            {
                CountryDTO countrydto = dto.Country;
                datamodel.CountryID = countrydto.CountryID;
                datamodel.AddressCountryAbbreviation = countrydto.Abbreviation;
                datamodel.AddressCountryCode         = countrydto.Code;
                datamodel.AddressCountryName         = countrydto.Name;
                datamodel.AddressCountryPhoneCode    = countrydto.PhoneCode;
            }

            if (dto.TypeCode != null)
            {
                TypeCodeDTO typecodedto = dto.TypeCode;
                datamodel.AddressTypeID                   = typecodedto.TypeCodeID;
                datamodel.AddressTypeCode                 = typecodedto.Code;
                datamodel.AddressTypeCodeClassTypeID      = typecodedto.ClassTypeID;
                datamodel.AddressTypeCodeDescription      = typecodedto.Description;
                datamodel.AddressTypeCodeName             = typecodedto.Name;
                datamodel.AddressTypeCodeParentTypeCodeID = typecodedto.ParentTypeCodeID;
            }

            return(datamodel);
        }
Ejemplo n.º 11
0
        public IAddress Build(IDataReader dataSource)
        {
            Guard.EnsureIsNotNull("dataSource", dataSource);

            var model = new AddressDataModel
            {
                Id              = dataSource.Get <Guid>(Columns.AddressId),
                EnteredDate     = dataSource.Get <DateTime>(Columns.EnteredDate),
                UpdatedDate     = dataSource.Get <DateTime>(Columns.UpdatedDate),
                Line1           = dataSource.Get <string>(Columns.Line1),
                Line2           = dataSource.Get <string>(Columns.Line2),
                City            = dataSource.Get <string>(Columns.City),
                StateProvinceId = dataSource.Get <Guid>(Columns.StateProvinceId),
                PostalCode      = dataSource.Get <string>(Columns.PostalCode)
            };

            AddValueFactory(model, LoaderKeys.GetStateProvinceByAddress,
                            new ParameterInfo(typeof(IAddress), model));
            AddValueFactory(model, LoaderKeys.GetCountryByAddress,
                            new ParameterInfo(typeof(IAddress), model));

            return(model);
        }
Ejemplo n.º 12
0
        public static void Update(AddressDataModel data, RequestProfile requestProfile)
        {
            var sql = Save(data, "Update", requestProfile);

            DBDML.RunSQL("Address.Update", sql, DataStoreKey);
        }
Ejemplo n.º 13
0
        public static string ToSQLParameter(AddressDataModel data, string dataColumnName)
        {
            var returnValue = "NULL";

            switch (dataColumnName)
            {
            case AddressDataModel.DataColumns.AddressId:
                if (data.AddressId != null)
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, AddressDataModel.DataColumns.AddressId, data.AddressId);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, AddressDataModel.DataColumns.AddressId);
                }
                break;

            case AddressDataModel.DataColumns.CityId:
                if (data.CityId != null)
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, AddressDataModel.DataColumns.CityId, data.CityId);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, AddressDataModel.DataColumns.CityId);
                }
                break;

            case AddressDataModel.DataColumns.City:
                if (!string.IsNullOrEmpty(data.City))
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, AddressDataModel.DataColumns.City, data.City);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, AddressDataModel.DataColumns.City);
                }
                break;

            case AddressDataModel.DataColumns.StateId:
                if (data.StateId != null)
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, AddressDataModel.DataColumns.StateId, data.StateId);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, AddressDataModel.DataColumns.StateId);
                }
                break;

            case AddressDataModel.DataColumns.State:
                if (!string.IsNullOrEmpty(data.State))
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, AddressDataModel.DataColumns.State, data.State);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, AddressDataModel.DataColumns.State);
                }
                break;

            case AddressDataModel.DataColumns.CountryId:
                if (data.CountryId != null)
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, AddressDataModel.DataColumns.CountryId, data.CountryId);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, AddressDataModel.DataColumns.CountryId);
                }
                break;

            case AddressDataModel.DataColumns.Country:
                if (!string.IsNullOrEmpty(data.Country))
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, AddressDataModel.DataColumns.Country, data.Country);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, AddressDataModel.DataColumns.Country);
                }
                break;

            case AddressDataModel.DataColumns.Address1:
                if (!string.IsNullOrEmpty(data.Address1))
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, AddressDataModel.DataColumns.Address1, data.Address1);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, AddressDataModel.DataColumns.Address1);
                }
                break;

            case AddressDataModel.DataColumns.Address2:
                if (!string.IsNullOrEmpty(data.Address2))
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, AddressDataModel.DataColumns.Address2, data.Address2);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, AddressDataModel.DataColumns.Address2);
                }
                break;

            case AddressDataModel.DataColumns.PostalCode:
                if (!string.IsNullOrEmpty(data.PostalCode))
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, AddressDataModel.DataColumns.PostalCode, data.PostalCode);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, AddressDataModel.DataColumns.PostalCode);
                }
                break;


            default:
                returnValue = BaseDataManager.ToSQLParameter(data, dataColumnName);
                break;
            }

            return(returnValue);
        }
Ejemplo n.º 14
0
        public static DataTable Search(AddressDataModel data, RequestProfile requestProfile)
        {
            var list = GetEntityDetails(data, requestProfile, 0);

            return(list.ToDataTable());
        }
Ejemplo n.º 15
0
        private static Address AdaptAddress(AddressDataModel dataModel)
        {
            var streets = dataModel.Streets?.Select(f => new Street(f.StreetName, f.StreetNumber)).ToList() ?? new List <Street>();

            return(new Address(dataModel.City, dataModel.Zip, streets, dataModel.Id));
        }