Ejemplo n.º 1
0
        public async Task <IActionResult> PutAspNetUserClaims(int id, AspNetUserClaims aspNetUserClaims)
        {
            if (id != aspNetUserClaims.Id)
            {
                return(BadRequest());
            }

            _context.Entry(aspNetUserClaims).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AspNetUserClaimsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id, AspNetUserClaims entity)
        {
            if (entity != null && ModelState.IsValid)
            {   //数据校验
                string currentPerson = GetCurrentPerson();
                //entity.UpdateTime = DateTime.Now;
                //entity.UpdatePerson = currentPerson;

                string returnValue = string.Empty;
                if (m_BLL.Edit(ref validationErrors, entity))
                {
                    LogClassModels.WriteServiceLog(Suggestion.UpdateSucceed + ",AspNetUserClaims信息的Id为" + id, "AspNetUserClaims"
                                                   );       //写入日志
                    return(Json(Suggestion.UpdateSucceed)); //提示更新成功
                }
                else
                {
                    if (validationErrors != null && validationErrors.Count > 0)
                    {
                        validationErrors.All(a =>
                        {
                            returnValue += a.ErrorMessage;
                            return(true);
                        });
                    }
                    LogClassModels.WriteServiceLog(Suggestion.UpdateFail + ",AspNetUserClaims信息的Id为" + id + "," + returnValue, "AspNetUserClaims"
                                                   );                  //写入日志
                    return(Json(Suggestion.UpdateFail + returnValue)); //提示更新失败
                }
            }
            return(Json(Suggestion.UpdateFail + "请核对输入的数据的格式")); //提示输入的数据的格式不对
        }
Ejemplo n.º 3
0
        public ActionResult Create(AspNetUserClaims entity)
        {
            if (entity != null && ModelState.IsValid)
            {
                string currentPerson = GetCurrentPerson();
                //entity.CreateTime = DateTime.Now;
                //entity.CreatePerson = currentPerson;


                string returnValue = string.Empty;
                if (m_BLL.Create(ref validationErrors, entity))
                {
                    LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",AspNetUserClaims的信息的Id为" + entity.Id, "AspNetUserClaims"
                                                   );//写入日志
                    return(Json(Suggestion.InsertSucceed));
                }
                else
                {
                    if (validationErrors != null && validationErrors.Count > 0)
                    {
                        validationErrors.All(a =>
                        {
                            returnValue += a.ErrorMessage;
                            return(true);
                        });
                    }
                    LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",AspNetUserClaims的信息," + returnValue, "AspNetUserClaims"
                                                   );                  //写入日志
                    return(Json(Suggestion.InsertFail + returnValue)); //提示插入失败
                }
            }

            return(Json(Suggestion.InsertFail + ",请核对输入的数据的格式")); //提示输入的数据的格式不对
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <AspNetUserClaims> > PostAspNetUserClaims(AspNetUserClaims aspNetUserClaims)
        {
            _context.AspNetUserClaims.Add(aspNetUserClaims);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAspNetUserClaims", new { id = aspNetUserClaims.Id }, aspNetUserClaims));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,ClaimType,ClaimValue")] AspNetUserClaims aspNetUserClaims)
        {
            if (id != aspNetUserClaims.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(aspNetUserClaims);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AspNetUserClaimsExists(aspNetUserClaims.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.AspNetUsers, "Id", "Id", aspNetUserClaims.UserId);
            return(View(aspNetUserClaims));
        }
Ejemplo n.º 6
0
        public ActionResult DeleteConfirmed(int id)
        {
            AspNetUserClaims aspNetUserClaims = db.AspNetUserClaims.Find(id);

            db.AspNetUserClaims.Remove(aspNetUserClaims);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
        public ActionResult DeleteConfirmed(int id)
        {
            AspNetUserClaims aspNetUserClaims = db.AspNetUserClaims.Find(id);

            db.AspNetUserClaims.Remove(aspNetUserClaims);
            db.SaveChanges();
            DisplaySuccessMessage("Has delete a AspNetUserClaims record");
            return(JsonRedirectToAction("Index"));
        }
Ejemplo n.º 8
0
 public ActionResult Edit([Bind(Include = "Id,UserId,ClaimType,ClaimValue")] AspNetUserClaims aspNetUserClaims)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aspNetUserClaims).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", aspNetUserClaims.UserId);
     return(View(aspNetUserClaims));
 }
        /// <summary>
        /// dohvati jedan po primary key-u
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public AspNetUserClaims Get(int Id)
        {
            AspNetUserClaims item = null;

            using (Entities data = new Entities())
            {
                item = data.AspNetUserClaims.Where(r => r.Id == Id).FirstOrDefault();
            }

            return(item);
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("Id,UserId,ClaimType,ClaimValue")] AspNetUserClaims aspNetUserClaims)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aspNetUserClaims);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.AspNetUsers, "Id", "Id", aspNetUserClaims.UserId);
            return(View(aspNetUserClaims));
        }
Ejemplo n.º 11
0
 public Task <IActionResult> Edit(AspNetUserClaims model)
 {
     return(Task.Factory.StartNew <IActionResult>(() =>
     {
         if (!ModelState.IsValid)
         {
             return Json(ExcutedResult.FailedResult("数据验证失败"));
         }
         AspNetUserClaimsRepository.Edit(model, false);
         return Json(ExcutedResult.SuccessResult());
     }));
 }
Ejemplo n.º 12
0
 public ActionResult Edit([Bind(Include = "Id,UserId,ClaimType,ClaimValue,AspNetUsers")] AspNetUserClaims aspNetUserClaims)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aspNetUserClaims).State = EntityState.Modified;
         db.SaveChanges();
         DisplaySuccessMessage("Has update a AspNetUserClaims record");
         return(JsonRedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", aspNetUserClaims.UserId);
     DisplayErrorMessage();
     return(PartialView(aspNetUserClaims));
 }
        /// <summary>
        /// Inserts a new claim in UserClaims table
        /// </summary>
        /// <param name="userClaim">User's claim to be added</param>
        /// <param name="userId">User's id</param>
        /// <returns></returns>
        public int Insert(Claim userClaim, string userId)
        {
            ConnectionService.ThreadVanityUrl = ConnectionName;

            AspNetUserClaims claim = new AspNetUserClaims();

            SetConnection(claim);
            claim.ClaimType  = userClaim.Type;
            claim.ClaimValue = userClaim.Value;
            claim.UserId     = userId;
            claim.Save();

            return(1);
        }
Ejemplo n.º 14
0
        // GET: AspNetUserClaims/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspNetUserClaims aspNetUserClaims = db.AspNetUserClaims.Find(id);

            if (aspNetUserClaims == null)
            {
                return(HttpNotFound());
            }
            return(View(aspNetUserClaims));
        }
Ejemplo n.º 15
0
 /// <summary>
 /// 创建一个AspNetUserClaims
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">一个AspNetUserClaims</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, AspNetUserClaims entity)
 {
     try
     {
         repository.Create(entity);
         return(true);
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// The add claim async.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <param name="claim">
        /// The claim.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public virtual Task AddClaimAsync([NotNull] AspNetUsers user, [NotNull] Claim claim)
        {
            CodeContracts.VerifyNotNull(user, nameof(user));
            CodeContracts.VerifyNotNull(claim, nameof(claim));

            var userClaim = new AspNetUserClaims
            {
                UserId = user.Id, ClaimType = claim.ValueType, ClaimValue = claim.Value
            };

            var result = this.GetRepository <AspNetUserClaims>().Insert(userClaim);

            this.UpdateUser(user);
            return(Task.FromResult(result));
        }
Ejemplo n.º 17
0
        // GET: AspNetUserClaims/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspNetUserClaims aspNetUserClaims = db.AspNetUserClaims.Find(id);

            if (aspNetUserClaims == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", aspNetUserClaims.UserId);
            return(View(aspNetUserClaims));
        }
        /// <summary>
        /// obriši item
        /// nije brisanje već postavljanje Deleted polja na true
        /// </summary>
        /// <param name="item">instanca entity objekta</param>
        /// <returns></returns>
        public bool Delete(AspNetUserClaims item)
        {
            bool uspjelo = false;

            using (KaFotkaEntities data = new KaFotkaEntities())
            {
                item.Deleted = true;
                data.Entry <AspNetUserClaims>(item).State = System.Data.EntityState.Modified;
                data.SaveChanges();

                uspjelo = true;
            }

            return(uspjelo);
        }
        public ActionResult Edit(string id, EditViewModel model)
        {
            try
            {
                var user = _ctx.AspNetUsers.Where(x => x.Id == id)?.FirstOrDefault();
                if (user == null)
                {
                    return(RedirectToAction("NotFound", "Error"));
                }
                user.UserName  = model.Username;
                user.Email     = model.Email;
                user.FirstName = model.FirstName;
                user.LastName  = model.LastName;

                if (!string.IsNullOrEmpty(model.Password))
                {
                    PasswordHasher <AspNetUsers> hasher = new PasswordHasher <AspNetUsers>();
                    var hash = hasher.HashPassword(user, model.Password);
                    user.PasswordHash = hash;
                }
                _ctx.Update(user);

                var claim = _ctx.AspNetUserClaims.Where(x => x.UserId == user.Id &&
                                                        x.ClaimType == JwtClaimTypes.Role &&
                                                        x.ClaimValue == "admin")?.FirstOrDefault();

                if (model.IsAdmin && claim == null)
                {
                    AspNetUserClaims claim1 = new AspNetUserClaims();
                    claim1.UserId     = user.Id;
                    claim1.ClaimType  = JwtClaimTypes.Role;
                    claim1.ClaimValue = "admin";

                    _ctx.Add(claim1);
                }
                else if (!model.IsAdmin && claim != null)
                {
                    _ctx.Remove(claim);
                }

                _ctx.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AspNetUserClaims = await _context.AspNetUserClaims
                               .Include(a => a.User).FirstOrDefaultAsync(m => m.Id == id);

            if (AspNetUserClaims == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AspNetUserClaims = await _context.AspNetUserClaims.FindAsync(id);

            if (AspNetUserClaims != null)
            {
                _context.AspNetUserClaims.Remove(AspNetUserClaims);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AspNetUserClaims = await _context.AspNetUserClaims
                               .Include(a => a.User).FirstOrDefaultAsync(m => m.Id == id);

            if (AspNetUserClaims == null)
            {
                return(NotFound());
            }
            ViewData["UserId"] = new SelectList(_context.AspNetUsers, "Id", "Id");
            return(Page());
        }
        /// <summary>
        /// spremi item
        /// insert ako nema Id
        /// update ako ima Id
        /// </summary>
        /// <param name="item">instanca entity objekta</param>
        /// <returns></returns>
        public bool Save(AspNetUserClaims item)
        {
            bool uspjelo = false;

            using (Entities data = new Entities())
            {
                data.AspNetUserClaims.Add(item);
                //ako ima Id onda je update
                if (item.Id != null)
                {
                    data.Entry <AspNetUserClaims>(item).State = System.Data.EntityState.Modified;
                }

                data.SaveChanges();

                uspjelo = true;
            }

            return(uspjelo);
        }
Ejemplo n.º 24
0
        public ActionResult Details(int id)
        {
            AspNetUserClaims item = m_BLL.GetById(id);

            return(View(item));
        }
Ejemplo n.º 25
0
 public ClaimViewModel(AspNetUserClaims claim)
 {
     this.Id         = claim.Id;
     this.ClaimType  = claim.ClaimType;
     this.ClaimValue = claim.ClaimValue;
 }
 public void Add(AspNetUserClaims entity)
 {
     db.AspNetUserClaims.Add(entity);
     db.SaveChanges();
 }
 public void Update(int id, AspNetUserClaims entity)
 {
     db.Update(entity);
     db.SaveChanges();
 }
        public ActionResult Create(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    AspNetUsers user = new AspNetUsers();
                    user.UserName           = model.Username;
                    user.Email              = model.Email;
                    user.NormalizedEmail    = model.Email.ToUpper();
                    user.NormalizedUserName = model.Username.ToUpper();
                    user.FirstName          = model.FirstName;
                    user.LastName           = model.LastName;
                    user.IsEnabled          = true;
                    user.SecurityStamp      = Guid.NewGuid().ToString();
                    PasswordHasher <AspNetUsers> hasher = new PasswordHasher <AspNetUsers>();
                    var hash = hasher.HashPassword(user, model.Password);
                    user.PasswordHash = hash;
                    user.Id           = Guid.NewGuid().ToString();
                    _ctx.Add(user);
                    _ctx.SaveChanges();

                    AspNetUserClaims claim = new AspNetUserClaims();
                    claim.UserId     = user.Id;
                    claim.ClaimType  = JwtClaimTypes.Name;
                    claim.ClaimValue = model.Username;
                    _ctx.Add(claim);

                    if (model.IsAdmin)
                    {
                        claim            = new AspNetUserClaims();
                        claim.UserId     = user.Id;
                        claim.ClaimType  = JwtClaimTypes.Role;
                        claim.ClaimValue = "admin";
                        _ctx.Add(claim);
                    }


                    claim            = new AspNetUserClaims();
                    claim.UserId     = user.Id;
                    claim.ClaimType  = JwtClaimTypes.GivenName;
                    claim.ClaimValue = model.FirstName;
                    _ctx.Add(claim);

                    claim            = new AspNetUserClaims();
                    claim.UserId     = user.Id;
                    claim.ClaimType  = JwtClaimTypes.FamilyName;
                    claim.ClaimValue = model.LastName;
                    _ctx.Add(claim);

                    claim            = new AspNetUserClaims();
                    claim.UserId     = user.Id;
                    claim.ClaimType  = JwtClaimTypes.Email;
                    claim.ClaimValue = model.Email;
                    _ctx.Add(claim);

                    claim            = new AspNetUserClaims();
                    claim.UserId     = user.Id;
                    claim.ClaimType  = JwtClaimTypes.EmailVerified;
                    claim.ClaimValue = true.ToString();
                    _ctx.Add(claim);

                    claim            = new AspNetUserClaims();
                    claim.UserId     = user.Id;
                    claim.ClaimType  = JwtClaimTypes.Scope;
                    claim.ClaimValue = "api1";
                    _ctx.Add(claim);

                    _ctx.SaveChanges();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    return(View());
                }
            }
            return(View());
        }