/// <summary> /// Creates the specified model. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> /// <exception cref="ArgumentException">Invalid values passed for creating history</exception> public async Task <DashboardLogHistory> Create(DashboardLogHistory model) { if (model == null) { logger.LogError("Invalid values passed for creating history"); throw new ArgumentException("Invalid values passed for creating history"); } try { var result = await dbContext.DashboardLogHistory.AddAsync(model); await dbContext.SaveChangesAsync().ConfigureAwait(true); return(model); } catch (Exception ex) { logger.LogError($"Create dashboard log history Error: {ex.Message}"); if (ex is DbUpdateException || ex is DbUpdateConcurrencyException) { return(null); } throw; } }
/// <summary> /// Updates the specified model. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> /// <exception cref="ArgumentException">Invalid values passed for updating history</exception> public async Task <DashboardLogHistory> Update(DashboardLogHistory model) { if (model == null) { logger.LogError("Invalid values passed for updating history"); throw new ArgumentException("Invalid values passed for updating history"); } try { var dashboardLogHistory = dbContext.DashboardLogHistory.Where(x => x.Id == model.Id).FirstOrDefault(); if (dashboardLogHistory != null) { dashboardLogHistory = model; var result = dbContext.DashboardLogHistory.Update(dashboardLogHistory); await dbContext.SaveChangesAsync(); return(model); } else { return(null); } } catch (Exception ex) { logger.LogError($"Update log history Error: {ex.Message}"); throw; } }