Beispiel #1
0
 public string AddUser(UserInfo objUserInfo)
 {
     objUserInfo.Status = Constants.NEWUSER;
     _context.UserInfos.AddRange(objUserInfo);
     _context.SaveChanges();
     return("Success");
 }
        public ActionResult Create([Bind(Include = "ID,UserName,UserPwd,Email,CreateDate,LastLoginDate")] UserInfoModel userInfoModel)
        {
            if (ModelState.IsValid)
            {
                db.UserInfoModels.Add(userInfoModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userInfoModel));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "Id,Name,Phone,Email,Gender")] Info info)
        {
            if (ModelState.IsValid)
            {
                db.Infoes.Add(info);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(info));
        }
        public static void EnsureSeedDataForContext(this UserInfoContext context)
        {
            SeedUserData(context);
            //SeedClassroomData(context);

            context.SaveChanges();
        }
Beispiel #5
0
 public User GetorCreateUser(string userId, string email)
 {
     if (_context.Users.FirstOrDefault(c => c.Id == userId) != null)
     {
         return(_context.Users.Where(c => c.Id == userId).Include(c => c.EducatorDetails).FirstOrDefault());
     }
     else
     {
         this._context.Users.Add(new Entities.User
         {
             Id          = userId,
             Description = email
                           //Name = name
                           //Description = country
         });
         _context.SaveChanges();
         return(_context.Users.Where(c => c.Id == userId).FirstOrDefault());
     }
 }
        //[Authorize]

        public IActionResult getorcreateuser([FromBody] UserDtoCreation uservariable)
        {
            //string userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;



            var userOrnull    = _userInfoRepository.ReturnUserorNull(uservariable.Id);
            var inviteOrnulll = _userInfoRepository.ReturnInviteorNull(uservariable.Id);

            //check to see if user is in the database
            //check to see if user is in the invite table
            if (userOrnull != null)
            {
                //ready to patch
                userOrnull.Authorization = uservariable.Authorization;
                _context.SaveChanges();
            }
            //if neither
            //add user to database
            if (userOrnull == null && inviteOrnulll == null)
            {
                var createdUser = _userInfoRepository.CreateUser(uservariable.Id, uservariable.Description, uservariable.Authorization);



                return(Ok(uservariable.Id));
            }

            // if in the database and not in the invite table
            //do nothing

            // if not in the database and in the invite table
            // add the user, add learner details, and enroll with the classroomID in the invite table
            if (userOrnull == null && inviteOrnulll != null)
            {
                var createdUser = _userInfoRepository.CreateUserLearnerAndEnroll(uservariable.Id, inviteOrnulll.Email, inviteOrnulll.ClassroomID);
                return(Ok(uservariable.Id));
            }
            // if in the database and in the invite table
            //do nothing

            return(Ok(uservariable.Id));
            //return CreatedAtRoute("GetUser", new
            //{
            //    id = createdUserToReturn.Id
            //}, createdUserToReturn);
        }
Beispiel #7
0
        public ActionResult Register(UserInfoModel userInfoModel)
        {
            string message = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    db.UserInfoModels.Add(userInfoModel);
                    db.SaveChanges();
                    ViewBag.Message = "用户创建成功!";
                }
            }
            catch
            {
                ViewBag.Message = "用户创建失败!";
            }
            return(View());
        }
        public void SeedData(UserInfoContext dbContext)
        {
            dbContext.AddRange(new List <UserInfoDto>()
            {
                new UserInfoDto()
                {
                    Name = "1", CreateTime = DateTime.Now
                },
                new UserInfoDto()
                {
                    Name = "2", CreateTime = DateTime.Now
                },
                new UserInfoDto()
                {
                    Name = "3", CreateTime = DateTime.Now
                }
            });

            dbContext.SaveChanges();
        }