Example #1
0
        public JsonResult _OperatorEdit(OperatorViewModel input)
        {
            _context.Get <ApplicationUser>(d => d.Id == input.Id).FirstOrDefault().UpdateDatetime = _context.GetNzTime();
            var opteratorRoles = _context.Get <IdentityUserRole>(d => d.UserId == input.Id).ToList();

            foreach (var item in opteratorRoles)
            {
                if (input.RolePosted != null)
                {
                    if (!input.RolePosted.ids.Any(d => d == item.RoleId))
                    {
                        var entity = _context.Get <IdentityUserRole>(d => d.RoleId == item.RoleId && d.UserId == input.Id).FirstOrDefault();
                        _context.GetTranscaiton().Entry(entity).State = EntityState.Deleted;
                    }
                }
                else
                {
                    var entity = _context.Get <IdentityUserRole>(d => d.RoleId == item.RoleId && d.UserId == input.Id).FirstOrDefault();
                    _context.GetTranscaiton().Entry(entity).State = EntityState.Deleted;
                }
            }
            _context.SaveChange();
            if (input.RolePosted != null)
            {
                foreach (var item in input.RolePosted.ids)
                {
                    if (!opteratorRoles.Any(d => d.RoleId == item))
                    {
                        _context.AddOneEntity <IdentityUserRole>(new IdentityUserRole {
                            UserId = input.Id, RoleId = item
                        });
                    }
                }
            }
            return(Json("1", JsonRequestBehavior.AllowGet));
        }
 void IRunOnEachRequest.Execute()
 {
     _httpContext.Items["_Transaction"] =
         _dbContext.GetTranscaiton().Database.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
 }