Example #1
0
        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);
        }
Example #2
0
        public void Rollback(string userId)
        {
            var dataApprove = _localUnitOfWork.DataContext.UpdateProfile_Requests.Where(d => d.UserId == userId && d.Status == Enum_UpdateProfile.Approve).OrderByDescending(d => d.UpdatedTime).FirstOrDefault();

            if (dataApprove != null)
            {
                bool isUpdateUserProfile             = false;
                BE.UpdateProfile_Request_Model model = JsonConvert.DeserializeObject <BE.UpdateProfile_Request_Model>(dataApprove.Current_Content_JSON);
                if (model.User_Profiles != null)
                {
                    List <string> ignore = new List <string>()
                    {
                        "LeftThumb_Photo", "RightThumb_Photo", "User_Photo2", "User_Photo1"
                    };
                    DAL.DBContext.User_Profiles userProfile = _localUnitOfWork.DataContext.User_Profiles.FirstOrDefault(d => d.UserId.Equals(userId));

                    var sourceProps = model.User_Profiles.GetType().GetProperties().Where(x => x.CanRead && !ignore.Contains(x.Name)).ToList();
                    var destProps   = userProfile.GetType().GetProperties()
                                      .Where(x => x.CanWrite && !ignore.Contains(x.Name))
                                      .ToList();
                    foreach (var sourceProp in sourceProps)
                    {
                        if (destProps.Any(x => x.Name == sourceProp.Name))
                        {
                            var _setProps = destProps.First(x => x.Name == sourceProp.Name);
                            var vauleNow  = _setProps.GetValue(userProfile);
                            var valueOld  = sourceProp.GetValue(model.User_Profiles);
                            if (_setProps.CanWrite && ((vauleNow == null && valueOld != null) || (vauleNow != null && valueOld == null) || (vauleNow != null && valueOld != null && !vauleNow.Equals(valueOld))))
                            {
                                _setProps.SetValue(userProfile, valueOld, null);
                                isUpdateUserProfile = true;
                            }
                        }
                    }
                    if (isUpdateUserProfile)
                    {
                        _localUnitOfWork.GetRepository <DAL.DBContext.User_Profiles>().Update(userProfile);
                    }
                }
                bool isUpdateAlternate_Addresses = false;
                if (model.Alternate_Addresses != null && !string.IsNullOrEmpty(model.Alternate_Addresses.Address_ID))
                {
                    DAL.DBContext.Address address = _localUnitOfWork.DataContext.Addresses.FirstOrDefault(d => d.Address_ID == model.Alternate_Addresses.Address_ID);
                    if (address != null)
                    {
                        var sourceProps = model.Alternate_Addresses.GetType().GetProperties().Where(x => x.CanRead).ToList();
                        var destProps   = address.GetType().GetProperties()
                                          .Where(x => x.CanWrite)
                                          .ToList();
                        foreach (var sourceProp in sourceProps)
                        {
                            if (destProps.Any(x => x.Name == sourceProp.Name))
                            {
                                var _setProps = destProps.First(x => x.Name == sourceProp.Name);
                                var vauleNow  = _setProps.GetValue(address);
                                var valueOld  = sourceProp.GetValue(model.Alternate_Addresses);
                                if (_setProps.CanWrite && ((vauleNow == null && valueOld != null) || (vauleNow != null && valueOld == null) || (vauleNow != null && valueOld != null && !vauleNow.Equals(valueOld))))
                                {
                                    _setProps.SetValue(address, valueOld, null);
                                    isUpdateAlternate_Addresses = true;
                                }
                            }
                        }
                        if (isUpdateAlternate_Addresses)
                        {
                            _localUnitOfWork.GetRepository <DAL.DBContext.Address>().Update(address);
                        }
                    }
                }
            }
        }