public async Task <IActionResult> PutAspNetRole(long id, AspNetRoleModel model)
        {
            var result = Check(id == model.Id, BadRequest).OkNull() ?? Check(Operation.Update).OkNull() ?? CheckIfMatch(model.Id);

            if (result.Fail())
            {
                return(result);
            }

            var entity = await DB_TABLE.FirstOrDefaultAsync(e => e.Id == model.Id);

            entity.Name             = model.Name;
            entity.NormalizedName   = model.Name.ToUpper();
            entity.ConcurrencyStamp = Guid.NewGuid().ToString();
            entity.PermissibleLevel = model.PermissibleLevel;

            DB.Entry(entity).State = EntityState.Modified;
            try { await DB.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DB_TABLE.Any(e => e.Id == id))
                                                                                        {
                                                                                            return(NotFound());
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            throw;
                                                                                        } }

            Log(DB_TABLE.GetName(), Operation.Update, null, model);

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutAspNetUser(long id, AspNetUserModel model)
        {
            var result = Check(id == model.Id, BadRequest).OkNull() ?? Check(Operation.Update).OkNull() ?? CheckIfMatch(model.Id);

            if (result.Fail())
            {
                return(result);
            }

            var entity = await DB_TABLE.FirstOrDefaultAsync(e => e.Id == model.Id);

            entity.Company_Id  = model.Company_Id;
            entity.UserName    = model.UserName;
            entity.Email       = model.Email;
            entity.PhoneNumber = model.PhoneNumber;
            var identityResult = await UserManager.UpdateAsync(entity);

            if (!identityResult.Succeeded)
            {
                return(BadRequest(string.Join(";", identityResult.Errors.Select(e => e.Description))));
            }

            Log(DB_TABLE.GetName(), Operation.Update, null, model);

            return(NoContent());
        }
        public async Task <ActionResult <AspNetUserLogModel> > GetAspNetUserLog(long id)
        {
            var result = Check(Operation.Read);

            if (result.Fail())
            {
                return(result);
            }

            var entity = await DB_TABLE
                         .FirstOrDefaultAsync(e => e.Id == id);

            result = Check(entity != null, NotFound).OkNull() ?? CheckETag(entity.GetHash());
            if (result.Fail())
            {
                return(result);
            }

            return(GetModel(entity));
        }