public ActionResult ClaimUpdate(Guid id)
        {
            Claim claim = null;

            using (BAuthDBContext dc = new BAuthDBContext())
            {
                claim = dc.Claims.Where(c => c.ClaimId == id).SingleOrDefault();

                var password  = Request.Form["password"];
                var newUserBD = new User()
                {
                    UserId     = claim.Email,
                    FirstName  = claim.FirstName,
                    LastName   = claim.LastName,
                    Email      = claim.Email,
                    password   = GetHash(password),
                    PictureUrl = "",
                    CreateDate = DateTime.Now,
                    Role       = "user"
                };

                dc.Users.Add(newUserBD);
                claim.UserId = newUserBD.UserId;
                dc.SaveChanges();
            }

            return(Redirect($"/обезщетение-списък/{claim.ClaimId}"));
        }
Esempio n. 2
0
        public static VMUser SyncUserToDatabase(VMUser user)
        {
            user.PictureUrl = user.PictureUrl ?? "";
            user.FirstName  = user.FirstName ?? "";
            user.LastName   = user.LastName ?? "";
            user.Email      = user.Email ?? "";
            user.Role       = user.Role ?? "";

            using (BAuthDBContext context = new BAuthDBContext())
            {
                var userDB = context.Users.Where(u => u.UserId == user.UserId).SingleOrDefault();
                if (userDB != null)
                {
                    user.Role = userDB.Role;
                    return(user);
                }
                user.Role = "";
                var newUserBD = new User()
                {
                    UserId     = user.UserId,
                    FirstName  = user.FirstName,
                    LastName   = user.LastName,
                    Email      = user.Email,
                    PictureUrl = user.PictureUrl,
                    CreateDate = DateTime.Now,
                    Role       = user.Role
                };

                context.Users.Add(newUserBD);
                context.SaveChanges();
                return(user);
            }
        }