Пример #1
0
        public IActionResult MyProfil()
        {
            if (HttpContext.Session.GetString("SessionUser") == null || HttpContext.Session.GetString("Token") == null)
            {
                return(RedirectToAction("Logout", "Account"));
            }

            var userInfo = JsonConvert.DeserializeObject <UserSession>(HttpContext.Session.GetString("SessionUser"));

            if (userInfo.Id == null)
            {
                return(RedirectToAction("Logout", "Account"));
            }

            var token = HttpContext.Session.GetString("Token");

            var user = _usersService.GetUserById(userInfo.Id, token);

            UserProfil userProfil = new UserProfil
            {
                Id          = user.Id,
                Civilite    = user.Civilite,
                Email       = user.Email,
                UserName    = user.UserName,
                FirstName   = user.FirstName,
                Name        = user.Name,
                DateOfBirth = user.DateOfBirth
            };

            return(View(userProfil));
        }
Пример #2
0
        public async Task <IActionResult> ResetQuiz(string id)
        {
            try
            {
                AspNetUser user = _context.AspNetUsers.Single(d => d.UserName == id);

                if (user == null)
                {
                    return(NotFound());
                }

                UserProfil userProfil = _context.UserProfils.Where(d => d.Id == user.Id).SingleOrDefault();
                user.QuizCompleted = false;

                _context.UserProfils.Remove(userProfil);
                _context.AspNetUsers.Update(user);
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
        public ActionResult EditProfil(UserProfil UP)
        {
            // ModelState.Remove("Date_start");
            if (ModelState.IsValid)
            {
                UP.UserId = (Session["LogedUserID"] as User).Id;
                int usId = (Session["LogedUserID"] as User).Id;

                var u = (from p in db.UserProfil
                         where p.UserId == usId
                         select p.Id).FirstOrDefault();
                UP.Id = u;


                db.Entry(UP).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           validationErrors.Entry.Entity.ToString(),
                                                           validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    throw raise;
                }
                return(RedirectToAction("AfterLogin", "Login"));
            }

            SizeDropDownList(UP.SizeId);
            BrandDropDownList(UP.BrandId);
            ColorDropDownList(UP.Color1Id);
            ColorDropDownList2(UP.Color2Id);

            return(View(UP));
        }
Пример #4
0
        //[Authorize(Policy = "FAB_ADMIN")]
        public UserProfil GetUserRights()
        {
            UserProfil   profil = new UserProfil();
            Contributeur user   = _usermanager.GetUser();

            if (user == null)
            {
                return(profil);
            }
            profil.UserId    = user.PkContributeur;
            profil.FirstName = user.Prenom;
            profil.LastName  = user.Nom;
            string appCode = _config.GetValue <string>("appCode");

            profil.RightsList = _usermanager.GetUserRights(user.PkContributeur, appCode);
            return(profil);
        }
Пример #5
0
        public async Task <ActionResult> QuizSubmit(int[] answer)
        {
            string accessToken = await HttpContext.GetTokenAsync("access_token");

            AspNetUser user   = null;
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            //Récupération de l'utilisateur courant
            string userString = await client.GetStringAsync(Configuration["URLAPI"] + "api/Account/getUserInfo");

            user = JsonConvert.DeserializeObject <AspNetUser>(userString);

            int query = (from item in answer
                         group item by item into g
                         orderby g.Count() descending
                         select g.Key).First();

            UserProfil userProfil = new UserProfil();

            userProfil.ProfilId = (short)query;
            userProfil.Id       = user.Id;

            user.QuizCompleted = true;

            try
            {
                _context.AspNetUsers.Update(user);

                _context.UserProfils.Add(userProfil);
                _context.SaveChanges();

                return(NoContent());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Пример #6
0
        public IActionResult MyProfil(UserProfil model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                if (HttpContext.Session.GetString("SessionUser") == null || HttpContext.Session.GetString("Token") == null)
                {
                    return(RedirectToAction("Logout", "Account"));
                }

                var userInfo = JsonConvert.DeserializeObject <UserSession>(HttpContext.Session.GetString("SessionUser"));

                var token = HttpContext.Session.GetString("Token");

                var user = _usersService.GetUserById(userInfo.Id, token);

                model.Id = user.Id;

                Users userNew = new Users
                {
                    Id          = model.Id,
                    Civilite    = model.Civilite,
                    Email       = model.Email,
                    UserName    = model.UserName,
                    FirstName   = model.FirstName,
                    Name        = model.Name,
                    DateOfBirth = model.DateOfBirth
                };

                _usersService.Update(userInfo.Id, userNew, token);

                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult EditProfil(int id)
        {
            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var u = from p in db.UserProfil
                    where p.UserId == id
                    select p;

            if (u.Count() == 0)
            {
                return(RedirectToAction("NewProfil", "Register", new { id = id }));
            }
            int        index = u.FirstOrDefault().Id;
            UserProfil up    = db.UserProfil.Find(index);

            SizeDropDownList(up.SizeId);
            BrandDropDownList(up.BrandId);
            ColorDropDownList(up.Color1Id);
            ColorDropDownList2(up.Color2Id);

            return(View(up));
        }
        public ActionResult NewProfil(UserProfil up)
        {
            //int adId=32;
            try
            {
                if (ModelState.IsValid)

                {
                    up.UserId = (Session["LogedUserID"] as User).Id;

                    db.UserProfil.Add(up);

                    //db.SaveChanges();
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                    {
                        Exception raise = dbEx;
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                string message = string.Format("{0}:{1}",
                                                               validationErrors.Entry.Entity.ToString(),
                                                               validationError.ErrorMessage);
                                // raise a new exception nesting
                                // the current instance as InnerException
                                raise = new InvalidOperationException(message, raise);
                            }
                        }
                        throw raise;
                    }
                    ModelState.Clear();
                }
                else
                {
                    SizeDropDownList(up.SizeId);
                    BrandDropDownList(up.BrandId);
                    ColorDropDownList(up.Color1Id);
                    ColorDropDownList2(up.Color2Id);



                    return(View(up));
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.)
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }


            SizeDropDownList(up.SizeId);
            BrandDropDownList(up.BrandId);
            ColorDropDownList(up.Color1Id);
            ColorDropDownList2(up.Color2Id);



            //return View(A);
            return(RedirectToAction("AfterLogin", "Login"));
        }
Пример #9
0
 public void UpdateFromView(AccountView view)
 {
     this.Pseudo = view.Pseudo;
     this.Email  = view.Email;
     this.Profil = UserProfil.CreateUserProfilFromView(view.Profil);
 }