Beispiel #1
0
        public static ViewModels.User CopyToViewModel(this DomainModels.User domainModel, ViewModels.User viewModel = null)
        {
            if (viewModel == null)
            {
                viewModel = new ViewModels.User();
            }

            viewModel.ID             = domainModel.ID;
            viewModel.LoginName      = domainModel.LoginName;
            viewModel.Name           = domainModel.Name;
            viewModel.Password       = domainModel.Password;
            viewModel.Age            = domainModel.Age.GetValueOrDefault();
            viewModel.Gender         = domainModel.Gender.HasValue ? Convert.ToInt32(domainModel.Gender.Value) : -1;
            viewModel.Email          = domainModel.Email;
            viewModel.BirthDate      = domainModel.BirthDate.GetValueOrDefault();
            viewModel.Married        = domainModel.Married.GetValueOrDefault();
            viewModel.Phone          = domainModel.Phone;
            viewModel.Position       = domainModel.Position;
            viewModel.Salary         = domainModel.Salary.GetValueOrDefault();
            viewModel.Education      = domainModel.Education;
            viewModel.School         = domainModel.School;
            viewModel.InUse          = domainModel.InUse;
            viewModel.IsAdmin        = domainModel.IsAdmin;
            viewModel.AddedTime      = domainModel.AddedTime;
            viewModel.DepartmentID   = domainModel.Department == null ? -1 : domainModel.Department.ID;
            viewModel.DepartmentName = domainModel.Department == null ? "" : domainModel.Department.Name;

            return(viewModel);
        }
Beispiel #2
0
        public static DomainModels.User CopyToDomainModel(this ViewModels.User viewModel, DomainModels.User domainModel = null)
        {
            if (domainModel == null)
            {
                domainModel = new DomainModels.User();
            }

            domainModel.ID        = viewModel.ID;
            domainModel.LoginName = viewModel.LoginName;
            domainModel.Password  = viewModel.Password ?? Util.GetMD5("");
            domainModel.Name      = viewModel.Name;
            domainModel.Age       = viewModel.Age;
            domainModel.Gender    = viewModel.Gender == 0 ? false : viewModel.Gender == 1 ? true : (bool?)null;
            domainModel.Email     = viewModel.Email;
            domainModel.BirthDate = viewModel.BirthDate;
            domainModel.Married   = viewModel.Married;
            domainModel.Phone     = viewModel.Phone;
            domainModel.Position  = viewModel.Position;
            domainModel.Salary    = viewModel.Salary;
            domainModel.Education = viewModel.Education;
            domainModel.School    = viewModel.School;
            domainModel.InUse     = viewModel.InUse;
            domainModel.AddedTime = viewModel.AddedTime;
            domainModel.State     = viewModel._state.Equals("added", StringComparison.CurrentCultureIgnoreCase) ? DomainModels.EntityState.Add :
                                    viewModel._state.Equals("removed", StringComparison.CurrentCultureIgnoreCase) ? DomainModels.EntityState.Delete : DomainModels.EntityState.Modify;

            return(domainModel);
        }