private void MarkEntityAsDeleted(CommentEntityFrameworkModel entity) { _dbContext.Entry(entity).State = EntityState.Deleted; }
public bool Update(TEntity entity) { Context.Entry(entity).State = EntityState.Modified; return(Context.SaveChanges() > 0); }
public ActionResult <ImageSaveCaptureTaskResponse> PostImageSaveCaptureTask(ImageSaveCaptureTaskRequest imageSaveCaptureTaskRequest) { //返回结果 ImageSaveCaptureTaskResponse imageSaveCaptureTaskResponse = new ImageSaveCaptureTaskResponse { TaskId = imageSaveCaptureTaskRequest.TaskId, Result = true, Msg = "" }; //获得TodoItem TodoItem item = _context.TodoItems.Find(imageSaveCaptureTaskRequest.TaskId); //获得当前TaskId的图像 List <ImageValue> imageValues = _context.ImageValues.Where(i => i.TaskId == imageSaveCaptureTaskRequest.TaskId).ToList(); //默认TodoItem不为null if (item != null) { item.RunMode = imageSaveCaptureTaskRequest.RunMode; item.MachineName = imageSaveCaptureTaskRequest.MachineName; if (string.IsNullOrWhiteSpace(item.MachineName)) { var ipAddress = Request.HttpContext.Connection.RemoteIpAddress; var clientName = ipAddress.ToString(); try { var ipHostEntry = Dns.GetHostEntry(ipAddress); clientName = ipHostEntry.HostName; } catch (Exception ex) { } item.MachineName = clientName; } item.CameraType = imageSaveCaptureTaskRequest.CameraType; item.CaptureCount = imageSaveCaptureTaskRequest.CaptureCount; //初始化的拍照次数小于用户指定的拍照次数,则初始化剩余的拍照图像 if (imageValues.Count < item.CaptureCount) { int currentCountAsName = imageValues.Count(); int currentCount = _context.ImageValues.Count(); for (int i = 1; i <= item.CaptureCount - imageValues.Count; i++) { _context.ImageValues.Add(new ImageValue { TaskId = imageSaveCaptureTaskRequest.TaskId, DateTime = DateTime.Now.ToUniversalTime(), Name = (currentCountAsName + i).ToString(), Value = "", Id = (currentCount + i), TodoItem = item }); } } item.CaptureFrequency = imageSaveCaptureTaskRequest.CaptureFrequency; //重建关联 imageValues.ForEach(i => i.TodoItem = item); //重新保存 _context.Entry(item).State = EntityState.Modified; imageValues.ForEach(i => { ImageValue imageValue = _context.ImageValues.Find(i.Id); _context.Entry(imageValue).State = EntityState.Modified; }); _context.SaveChanges(); } else { imageSaveCaptureTaskResponse.Msg = "Can not find todoitem"; imageSaveCaptureTaskResponse.Result = false; } return(imageSaveCaptureTaskResponse); }
public void Update(T entity) { _context.Entry(entity).State = EntityState.Modified; }
public async Task UpdateAsync(TodoItem item) { _context.Entry(item).State = EntityState.Modified; await _context.SaveChangesAsync(); }
public void Update(TodoItem todoItem) { _context.Entry(todoItem).State = EntityState.Modified; _context.SaveChanges(); }
public async Task Update(long id, T entity) { _context.Entry(entity).State = EntityState.Modified; await _context.SaveChangesAsync(); }
public Task PutItemAsync(TodoItem item) { _dbContext.Entry(item).State = EntityState.Modified; return(_dbContext.SaveChangesAsync()); }
private async Task <AuthResult> VerifyToken(TokenRequest tokenRequest) { var jwtHandler = new JwtSecurityTokenHandler(); var validationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_jwtConfig.Secret)), ValidateIssuer = true, ValidIssuer = _jwtConfig.Issuer, ValidateAudience = true, ValidAudience = _jwtConfig.Audience, RequireExpirationTime = true, ValidateLifetime = false, ClockSkew = TimeSpan.Zero }; try { var tokenInVerification = jwtHandler.ValidateToken(tokenRequest.Token, validationParameters, out var validatedToken); if (validatedToken is JwtSecurityToken jwtSecurityToken) { var correctAlg = jwtSecurityToken.Header.Alg.Equals(SecurityAlgorithms.HmacSha512, StringComparison.InvariantCultureIgnoreCase); if (!correctAlg) { return(null); } } var utcExpiryDate = long.Parse(tokenInVerification.Claims.FirstOrDefault(x => x.Type == JwtRegisteredClaimNames.Exp)?.Value ?? string.Empty); if (utcExpiryDate <= 0) { return(new AuthResult() { Success = false, Errors = new List <string>() { "Invalid Jwt" } }); } var expiryDate = UnixTimeStampToDateTime(utcExpiryDate); if (expiryDate > DateTime.UtcNow) { return(new AuthResult() { Success = false, Errors = new List <string>() { "Jwt not expired" } }); } var storedRefreshToken = await _dbContext.RefreshTokens.FirstOrDefaultAsync(x => x.Token == tokenRequest.RefreshToken); if (storedRefreshToken == null) { return(new AuthResult() { Errors = new List <string>() { "refresh token doesnt exist" }, Success = false }); } if (DateTime.UtcNow > storedRefreshToken.ExpiryData) { return(new AuthResult() { Success = false, Errors = new List <string>() { "Refreshtoken has expired, login required" } }); } if (storedRefreshToken.IsUsed) { return(new AuthResult() { Success = false, Errors = new List <string>() { "Token already used" } }); } if (storedRefreshToken.IsRevoked) { return(new AuthResult() { Success = false, Errors = new List <string>() { "Token has been revoked" } }); } var jti = tokenInVerification.Claims.SingleOrDefault(x => x.Type == JwtRegisteredClaimNames.Jti).Value; if (storedRefreshToken.JwtId != jti) { return(new AuthResult() { Success = false, Errors = new List <string>() { "Token does not match" }, }); } storedRefreshToken.IsUsed = true; _dbContext.Entry(storedRefreshToken).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); var dbUser = await _userManager.FindByIdAsync(storedRefreshToken.UserId); return(await GenerateJwtAsync(dbUser)); } catch (Exception e) { _logger.LogError(e.Message); throw; } }
// PUT api/todo/5 public HttpResponseMessage Put(Todo todo) { _ctx.Entry(todo).State = EntityState.Modified; _ctx.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, todo)); }
public ActionResult <ScaleSaveTaskResponse> PostScaleSaveTask(ScaleSaveTaskRequest scaleSaveTask) { //返回结果 ScaleSaveTaskResponse scaleSaveTaskResponse = new ScaleSaveTaskResponse { TaskId = scaleSaveTask.TaskId, Msg = "", Result = true }; //获得TodoItem TodoItem item = _context.TodoItems.Find(scaleSaveTask.TaskId); //获得当前TaskId的电子秤参数 ScaleParams scaleParams = _context.ScaleParams.FirstOrDefault(m => m.TaskId == scaleSaveTask.TaskId); //获得当前TaskId的秤重值 List <ScaleValue> scaleValues = _context.ScaleValues.Where(s => s.TaskId == scaleSaveTask.TaskId).ToList(); //默认TodoItem不为null if (item != null) { item.ScaleType = scaleSaveTask.ScaleType; item.ScaleName = scaleSaveTask.ScaleName; item.ScaleCount = scaleSaveTask.ScaleCount; //初始化的称重次数小于用户指定的称重次数,则初始化剩余的称重次数 if (scaleValues.Count < item.ScaleCount) { int currentCountAsName = scaleValues.Count(); int currentCount = _context.ScaleValues.Count(); for (int i = 1; i <= item.ScaleCount - scaleValues.Count; i++) { _context.ScaleValues.Add(new ScaleValue { TaskId = scaleSaveTask.TaskId, DateTime = DateTime.Now.ToUniversalTime(), Name = (currentCountAsName + i).ToString(), ScaleValueId = (currentCount + i), TodoItem = item, Value = 0 }); } } item.ScaleFrequency = scaleSaveTask.ScaleFrequency; scaleParams.ScalePort = scaleSaveTask.ScaleParams.ScalePort; item.ScaleParams = scaleParams; //重建关联 scaleParams.todoItem = item; scaleValues.ForEach(m => m.TodoItem = item); //重新保存 _context.Entry(item).State = EntityState.Modified; ScaleParams scaleParams1 = _context.ScaleParams.Find(scaleParams.ScaleParamId); _context.Entry(scaleParams1).State = EntityState.Modified; scaleValues.ForEach(m => { ScaleValue scaleValue = _context.ScaleValues.Find(m.ScaleValueId); _context.Entry(scaleValue).State = EntityState.Modified; }); _context.SaveChanges(); } else { scaleSaveTaskResponse.Msg = "Can not find todoitem"; scaleSaveTaskResponse.Result = false; } //返回结果 return(scaleSaveTaskResponse); }
public void Add(T entidade) { context.Entry <T>(entidade).State = System.Data.Entity.EntityState.Added; }
public async Task UpdateAsync(T entity) { _dbContext.Entry(entity).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); }
public Task UpdateAsync(TodoList aggregate) { _context.Entry(aggregate).State = EntityState.Modified; return(Task.CompletedTask); }
public void Update(TodoItem item) { _context.Entry(item).State = EntityState.Modified; }
public void Atualizar(TodoItem todo) { _context.Entry(todo).State = EntityState.Modified; _context.SaveChanges(); }
/// <summary> /// actualiza el item dado /// </summary> /// <param name="todoItem"></param> public void UpdateTodoItem(TodoItem todoItem) { _context.Entry(todoItem).State = EntityState.Modified; }
public virtual void Add(T entity) { EntityEntry dbEntityEntry = _context.Entry <T>(entity); _context.Set <T>().Add(entity); }
public void Update(T entity) { _context.Set <T>().Attach(entity); _context.Entry(entity).State = EntityState.Modified; }
public void Update(T item) { db.Entry(item).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); }