Ejemplo n.º 1
0
        public async Task <IActionResult> Insert()
        {
            var user = new UserModel();
            await _userService.Insert(user.Adapt <UserDto>());

            return(new ObjectResult(""));
        }
Ejemplo n.º 2
0
        public virtual TblUsers PrepareTblUsers(UserModel user)
        {
            var result = user.Adapt <TblUsers>();

            result.UserName = user.Email;
            return(result);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> SignUp([FromBody] UserModel model)
        {
            var newUser = model.Adapt <UserEntity>();

            var result = await userManager.CreateAsync(newUser, model.Password);

            if (result.Succeeded)
            {
                if (!string.IsNullOrEmpty(model.RoleName))
                {
                    result = await userManager.AddToRoleAsync(newUser, model.RoleName);
                }

                if (result.Succeeded)
                {
                    return(Ok());
                }

                return(Problem(result.Errors.First().Description, null, StatusCodes.Status500InternalServerError));
            }
            else
            {
                return(Problem(result.Errors.First().Description, null, StatusCodes.Status500InternalServerError));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> GetUserAsync()
        {
            int userId = HttpContext.GetUserId();

            UserModel result = await _accountService.GetUserAsync(userId);

            return(Ok(result.Adapt <UserResponse>()));
        }
Ejemplo n.º 5
0
        public async Task Reconnect(ReconnectToGameEvent e, string connectionid)
        {
            RoomModel room = await _rooms.GetRoomById(e.RoomId);

            UserModel user = room.Users.First(u => u.Token == e.Token && u.Disconnected);

            if (user == null)
            {
                throw new ArgumentException();
            }
            user.Disconnected = false;
            user.Token        = connectionid;
            JoinRoomEvent jre = room.Adapt <JoinRoomEvent>();

            jre.Token  = user.Token;
            jre.RoomId = e.RoomId;
            jre.UserId = user.Id;
            await _hub.Clients.Client(connectionid).SendAsync("JoinRoomEvent", jre);

            await _hub.Groups.AddToGroupAsync(connectionid, e.RoomId);

            await _hub.Clients.Client(connectionid).SendAsync("UpdateGameState", room.Game);

            await _hub.Clients.GroupExcept(e.RoomId, connectionid)
            .SendAsync("UserJoinedRoom", user.Adapt <UserJoinedRoomEvent>());

            List <Task> cards = new();

            foreach (CardModel card in user.CardDeck)
            {
                cards.Add(_hub.Clients.Client(connectionid).SendAsync("RefillCards", card));
            }
            await Task.WhenAll(cards);

            await _rooms.Save(e.RoomId, room);
        }
Ejemplo n.º 6
0
        public int AddOrEditUser(UserModel user, UserTokenModel curUser)
        {
            if (user.UserId > 0)
            {
                goto editUser;
            }

            var ue = user.Adapt <User>();

            ue.Password = "******";
            var pwd = Atom.Lib.Security.CryptographyUtils.Pwd(ue.Password);

            ue.Password = pwd.Item1;
            ue.Salt     = pwd.Item2;
            ue.LoginId  = string.IsNullOrWhiteSpace(ue.LoginId) ? Guid.NewGuid().ToString("N") : user.LoginId;
            //ue.SSN = ue.MobilePhone;
            ue.AddUserId  = curUser.UserId;
            ue.EditUserId = curUser.UserId;
            ue.AddTime    = DateTime.Now;
            ue.EditTime   = DateTime.Now;
            db.Set <User>().Add(ue);
            db.SaveChanges();

            if (user.UserType == 1)
            {
                var uex = user.Adapt <UserExtLearner>();
                uex.AddUserId  = curUser.UserId;
                uex.EditUserId = curUser.UserId;
                uex.AddTime    = DateTime.Now;
                uex.EditTime   = DateTime.Now;
                uex.UserId     = ue.UserId;
                db.Set <UserExtLearner>().Add(uex);
            }
            else if (user.UserType == 2)
            {
                var uext = user.Adapt <UserTecherExt>();
                uext.AddUserId  = curUser.UserId;
                uext.EditUserId = curUser.UserId;
                uext.AddTime    = DateTime.Now;
                uext.EditTime   = DateTime.Now;
                uext.UserId     = ue.UserId;
                db.Set <UserTecherExt>().Add(uext);
            }

            var uwr = new UserWorkRole();

            uwr.IsValid    = true;
            uwr.AddUserId  = curUser.UserId;
            uwr.EditUserId = curUser.UserId;
            uwr.AddTime    = DateTime.Now;
            uwr.EditTime   = DateTime.Now;
            uwr.RoleCode   = user.UserType == 1 ? "learner" : "trainer";
            uwr.UserId     = ue.UserId;
            db.Set <UserWorkRole>().Add(uwr);

            return(db.SaveChanges());

editUser:

            var exist = db.Set <User>().Find(user.UserId);

            exist.UserName    = user.UserName;
            exist.MobilePhone = user.MobilePhone;
            //exist.SSN = user.MobilePhone;
            exist.Gender          = user.Gender;
            exist.HeadImg         = user.HeadImg;
            exist.BirthDay        = user.BirthDay;
            exist.EditTime        = DateTime.Now;
            exist.EditUserId      = curUser.UserId;
            exist.IsValid         = user.IsValid;
            db.Entry(exist).State = System.Data.Entity.EntityState.Modified;

            if (user.UserType == 1)
            {
                var existuex = db.Set <UserExtLearner>().FirstOrDefault(t => t.UserId == user.UserId);

                existuex.School          = user.School;
                existuex.Grade           = user.Grade;
                existuex.Likes           = user.Likes;
                existuex.Disposition     = user.Disposition;
                existuex.LikesStuff      = user.LikesStuff;
                existuex.HasEn           = user.HasEn;
                existuex.IsEarlyEdu      = user.IsEarlyEdu;
                existuex.IsHasAllergy    = user.IsHasAllergy;
                existuex.ParentName      = user.ParentName;
                existuex.ParentPhone     = user.ParentPhone;
                existuex.ParentGrade     = user.ParentGrade;
                existuex.ParentDoing     = user.ParentDoing;
                existuex.SendPeople      = user.SendPeople;
                existuex.SendPhone       = user.SendPhone;
                existuex.SendType        = user.SendType;
                existuex.TechPeople      = user.TechPeople;
                existuex.IsHasEduType    = user.IsHasEduType;
                existuex.HasKnowStdudent = user.HasKnowStdudent;
                existuex.ComLearnType    = user.ComLearnType;
                existuex.EditUserId      = curUser.UserId;
                existuex.EditTime        = DateTime.Now;
                db.Entry(existuex).State = System.Data.Entity.EntityState.Modified;
            }
            else if (user.UserType == 2)
            {
                var existuext = db.Set <UserTecherExt>().FirstOrDefault(t => t.UserId == user.UserId);
                existuext.TechHistory     = user.TechHistory;
                existuext.Certificate     = user.Certificate;
                existuext.EditUserId      = curUser.UserId;
                existuext.EditTime        = DateTime.Now;
                db.Entry(existuext).State = System.Data.Entity.EntityState.Modified;
            }
            return(db.SaveChanges());
        }