Exemplo n.º 1
0
        public void destroyUserInfo(ViewUser viewuser) { 
        
            
            Delete(a=>a.UserId == viewuser.UserId);
            DataContext.Commit();

        }
Exemplo n.º 2
0
        public void updateUserInfo(ref ViewUser viewuser) {

            AutoMapper.IMapper mapper;
            AutoMapper.MapperConfiguration config;
            System.Data.Entity.EntityState entitystate;
            var currentTime = DateTime.Now;

            string guid = string.Empty;

            if (string.IsNullOrEmpty(viewuser.UserId))
            {

                entitystate = System.Data.Entity.EntityState.Added;
                viewuser.UserId = one.Core.Utilities.ShortGuid();
                viewuser.CreateTime = currentTime;

            }
            else 
            {
                entitystate = System.Data.Entity.EntityState.Modified;
                viewuser.LastUpdateTime = currentTime;
            }


            config = new AutoMapper.MapperConfiguration(cfg => cfg.CreateMap<ViewUser, Auth_Users>());
            mapper = config.CreateMapper();
            Auth_Users user = mapper.Map<Auth_Users>(viewuser);

            config = new AutoMapper.MapperConfiguration(cfg => cfg.CreateMap<ViewUser, Auth_UserInfor>());
            mapper = config.CreateMapper();
            Auth_UserInfor userInfo = mapper.Map<Auth_UserInfor>(viewuser);

            DataContext.Auth_Users.Attach(user);
            DataContext.Auth_UserInfor.Attach(userInfo);

            if (entitystate == System.Data.Entity.EntityState.Added)
            {
                DataContext.Entry(user).State = System.Data.Entity.EntityState.Added;
                DataContext.Entry(userInfo).State = System.Data.Entity.EntityState.Added;
            }
            else
            {
                DataContext.Entry(user).Property(s => s.UserName).IsModified = true;
                DataContext.Entry(user).Property(s => s.Email).IsModified = true;
                DataContext.Entry(user).Property(s => s.PhoneNumber).IsModified = true;
                DataContext.Entry(userInfo).Property(a => a.Describe).IsModified = true;
                DataContext.Entry(userInfo).Property(a => a.Mobile).IsModified = true;
                DataContext.Entry(userInfo).Property(a => a.LastUpdateTime).IsModified = true;
                DataContext.Entry(userInfo).Property(a => a.Name).IsModified = true;
                DataContext.Entry(userInfo).Property(a => a.QQ).IsModified = true;
                DataContext.Entry(userInfo).Property(a => a.Remark).IsModified = true;
                DataContext.Entry(userInfo).Property(a => a.Department).IsModified = true;
            }

            DataContext.Commit();
        }