private void UpdateOrInsert(BE.Address model, IUnitOfWork unitOfWork) { var AddressRespon = unitOfWork.GetRepository <Trinity.DAL.DBContext.Address>(); DBContext.Address dbAddress = AddressRespon.GetById(model.Address_ID); if (dbAddress == null) { dbAddress = new Trinity.DAL.DBContext.Address(); dbAddress.Address_ID = model.Address_ID; dbAddress.BlkHouse_Number = model.BlkHouse_Number; dbAddress.FlrUnit_Number = model.FlrUnit_Number; dbAddress.Street_Name = model.Street_Name; dbAddress.Country = model.Country; dbAddress.Postal_Code = model.Postal_Code; AddressRespon.Add(dbAddress); unitOfWork.Save(); } else { dbAddress.BlkHouse_Number = model.BlkHouse_Number; dbAddress.FlrUnit_Number = model.FlrUnit_Number; dbAddress.Street_Name = model.Street_Name; dbAddress.Country = model.Country; dbAddress.Postal_Code = model.Postal_Code; AddressRespon.Update(dbAddress); unitOfWork.Save(); } }
public BE.Address GetAddByUserId(string userId, bool isOther = false) { UserProfile user = GetProfile(userId); if (user == null) { return(null); } string AddressID = isOther ? user.Other_Address_ID : user.Residential_Addess_ID; if (string.IsNullOrEmpty(AddressID)) { return(null); } DBContext.Address addressData = _localUnitOfWork.DataContext.Addresses.FirstOrDefault(a => a.Address_ID == AddressID); if (addressData != null) { var address = new BE.Address { Address_ID = addressData.Address_ID, BlkHouse_Number = addressData.BlkHouse_Number, Country = addressData.Country, FlrUnit_Number = addressData.FlrUnit_Number, Postal_Code = addressData.Postal_Code, Street_Name = addressData.Street_Name }; return(address); } return(null); }
public Response <BE.Address> GetAddressByUserId(string userId, bool isOther = false) { User_Profiles dbUserProfile = null; DBContext.Address dbAddress = null; if (EnumAppConfig.IsLocal) { dbUserProfile = _localUnitOfWork.DataContext.User_Profiles.FirstOrDefault(u => u.UserId == userId); if (dbUserProfile != null) { var addressId = dbUserProfile.Residential_Addess_ID; if (isOther) { addressId = dbUserProfile.Other_Address_ID; } dbAddress = _localUnitOfWork.DataContext.Addresses.FirstOrDefault(a => a.Address_ID == addressId); } } else { dbUserProfile = _centralizedUnitOfWork.DataContext.User_Profiles.FirstOrDefault(u => u.UserId == userId); if (dbUserProfile != null) { var addressId = dbUserProfile.Residential_Addess_ID; if (isOther) { addressId = dbUserProfile.Other_Address_ID; } dbAddress = _centralizedUnitOfWork.DataContext.Addresses.FirstOrDefault(a => a.Address_ID == addressId); } } if (dbUserProfile != null) { if (dbAddress != null) { var address = new BE.Address { Address_ID = dbAddress.Address_ID, BlkHouse_Number = dbAddress.BlkHouse_Number, Country = dbAddress.Country, FlrUnit_Number = dbAddress.FlrUnit_Number, Postal_Code = dbAddress.Postal_Code, Street_Name = dbAddress.Street_Name }; return(new Response <BE.Address>((int)EnumResponseStatuses.Success, EnumResponseMessage.Success, address)); } } return(new Response <BE.Address>((int)EnumResponseStatuses.ErrorSystem, EnumResponseMessage.ErrorSystem, null)); }
public bool ARKUpdateProfile(string UserID, Dictionary <string, Dictionary <string, object> > dataUpdate, List <string> arrayScanDocument, out BE.UserProfile User_Profiles_New, out BE.Address Alternate_Addresses_New, out Guid?IDDocuemnt_Re) { IDDocuemnt_Re = null; User_Profiles_New = null; Alternate_Addresses_New = null; bool isUpdateUser_Profiles = false; bool isSaveDataBase = false; CreateUserProfileIfNotExit(UserID); Nullable <Guid> IDDocuemnt = null; if (arrayScanDocument.Count > 0) { IDDocuemnt = new DAL_UploadedDocuments().Insert(arrayScanDocument, UserID); } DAL.DBContext.User_Profiles userProfile = _localUnitOfWork.DataContext.User_Profiles.FirstOrDefault(d => d.UserId.Equals(UserID)); DAL.DBContext.Address Alternate_Addresses = null; if (!string.IsNullOrEmpty(userProfile.Other_Address_ID)) { Alternate_Addresses = _localUnitOfWork.DataContext.Addresses.FirstOrDefault(d => d.Address_ID.Equals(userProfile.Other_Address_ID)); } if (dataUpdate.ContainsKey("Alternate_Addresses")) { if (Alternate_Addresses == null) { Alternate_Addresses = new DBContext.Address() { Address_ID = Guid.NewGuid().ToString().Trim() }; foreach (var item in dataUpdate["Alternate_Addresses"]) { PropertyInfo propertyInfo = Alternate_Addresses.GetType().GetProperty(item.Key); propertyInfo.SetValue(Alternate_Addresses, item.Value == null ? null : Convert.ChangeType(item.Value, propertyInfo.PropertyType), null); } userProfile.Other_Address_ID = Alternate_Addresses.Address_ID; _localUnitOfWork.GetRepository <DAL.DBContext.Address>().Add(Alternate_Addresses); isUpdateUser_Profiles = true; isSaveDataBase = true; } else { bool isUpdateAddress = false; foreach (var item in dataUpdate["Alternate_Addresses"]) { PropertyInfo propertyInfo = Alternate_Addresses.GetType().GetProperty(item.Key); propertyInfo.SetValue(Alternate_Addresses, item.Value == null ? null : Convert.ChangeType(item.Value, propertyInfo.PropertyType), null); isSaveDataBase = true; isUpdateAddress = true; } if (isUpdateAddress) { _localUnitOfWork.GetRepository <DAL.DBContext.Address>().Update(Alternate_Addresses); } } } if (dataUpdate.ContainsKey("User_Profiles")) { foreach (var item in dataUpdate["User_Profiles"]) { PropertyInfo propertyInfo = userProfile.GetType().GetProperty(item.Key); var underlyingType = Nullable.GetUnderlyingType(propertyInfo.PropertyType); propertyInfo.SetValue(userProfile, item.Value == null ? null : Convert.ChangeType(item.Value, underlyingType ?? propertyInfo.PropertyType), null); isUpdateUser_Profiles = true; isSaveDataBase = true; } } if (IDDocuemnt.HasValue) { userProfile.Document_ID = IDDocuemnt.Value; isUpdateUser_Profiles = true; isSaveDataBase = true; IDDocuemnt_Re = IDDocuemnt.Value; } if ((!userProfile.Employment_Start_Date.HasValue && userProfile.Employment_End_Date.HasValue) || (userProfile.Employment_Start_Date.HasValue && userProfile.Employment_End_Date.HasValue && userProfile.Employment_Start_Date.Value >= userProfile.Employment_End_Date.Value)) { Lib.LayerWeb.ShowMessage("<b>Employment Start Date</b> must be less than <b>Employment End Date</b>"); return(false); } else { if (isUpdateUser_Profiles) { _localUnitOfWork.GetRepository <DAL.DBContext.User_Profiles>().Update(userProfile); } if (isSaveDataBase) { _localUnitOfWork.Save(); } User_Profiles_New = userProfile.Map <BE.UserProfile>(); Alternate_Addresses_New = Alternate_Addresses.Map <BE.Address>();; } return(true); }