/// <summary> /// Adds the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> AddAsync(RecordLockDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { FAR_RecordLock add = context.FAR_RecordLock.Create(); add.ProcessHistoryId = entity.ProcessHistoryId; add.LockBy = entity.LockBy; add.LockDate = entity.LockDate; add.MasterId = entity.MasterId; add.ReleaseDate = entity.ReleaseDate; add.LastUpdatedBy = entity.LastUpdatedBy; add.LastUpdate = DateTime.Now; context.Entry<FAR_RecordLock>(add).State = System.Data.Entity.EntityState.Added; result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCESS : SaveResult.FAILURE; } } catch (Exception ex) { _logService.Error(ex.Message, ex); result = SaveResult.FAILURE; } return result; }
/// <summary> /// Deletes the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> DeleteAsync(RecordLockDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { var record = context.FAR_RecordLock.Single(x => x.Id == entity.Id && x.IsDeleted == false); record.IsDeleted = true; record.LastUpdate = DateTime.Now; record.LastUpdatedBy = entity.LastUpdatedBy; context.Entry<FAR_RecordLock>(record).State = System.Data.Entity.EntityState.Modified; result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCESS : SaveResult.FAILURE; } } catch (Exception ex) { _logService.Error(ex.Message, ex); result = SaveResult.FAILURE; } return result; }
/// <summary> /// Updates the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public SaveResult Update(RecordLockDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { var update = context.FAR_RecordLock.Single(x => x.Id == entity.Id && x.IsDeleted == false); update.ProcessHistoryId = entity.ProcessHistoryId; update.LockBy = entity.LockBy; update.LockDate = entity.LockDate; update.MasterId = entity.MasterId; update.ReleaseDate = entity.ReleaseDate; update.LastUpdatedBy = entity.LastUpdatedBy; update.LastUpdate = DateTime.Now; context.Entry<FAR_RecordLock>(update).State = System.Data.Entity.EntityState.Modified; result = context.SaveChanges() > 0 ? SaveResult.SUCESS : SaveResult.FAILURE; } } catch (Exception ex) { _logService.Error(ex.Message, ex); result = SaveResult.FAILURE; } return result; }