/// <summary> /// Update calculation. /// </summary> /// <param name="calculation"> Calculation entity. </param> /// <returns></returns> public async Task UpdateAsync(Calculation calculation) { _logger.LogInformation("Inside the repository about to call UpdateAsync."); _dbContext.Entry(calculation).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); }
public async Task <bool> CreateAsync(ServerFormula entity) { if (!Validator.Validate(entity)) { return(false); } db.Formulas.Add(entity); return(await db.SaveChangesAsync() > 0); }
public async Task SaveOperation(string ip, string expression) { User user = db.Users.FirstOrDefault(u => u.Ip == ip) ?? new User(); if (user.Id == 0) { user.Ip = ip; db.Users.Add(user); await db.SaveChangesAsync(); } Operation operation = new Operation { UserId = user.Id, Expresssion = expression, TimeOfOperation = DateTime.Now }; db.Operations.Add(operation); await db.SaveChangesAsync(); }
public async Task AddConstant(string name, string value) { var constant = new Entities.Constant() { Id = Guid.NewGuid(), Name = name, Value = value, ModifyDate = System.DateTime.UtcNow }; _context.Constants.Add(constant); await _context.SaveChangesAsync().ConfigureAwait(false); }
public async Task <IActionResult> Add([FromBody] NumCalculator number) { try { var data = JsonConvert.SerializeObject(number); _logger.LogInformation(string.Format(Messages.Request, "Add", data)); await _dbContext.Reports.AddAsync(new Report { MethodId = 1, VALUE = string.Format(Messages.Request, "Add", data) }); await _dbContext.SaveChangesAsync(); var response = await _calculatorSoap.AddAsync(number.FirstNum, number.SecondNum); await _dbContext.Reports.AddAsync(new Report { MethodId = 1, VALUE = string.Format(Messages.Response, "Add", response, data) }); await _dbContext.SaveChangesAsync(); _logger.LogInformation("The control is succesfully", response); return(Ok(response)); } catch (Exception ex) { _logger.LogError(ex.Message); return(new StatusCodeResult((int)HttpStatusCode.InternalServerError)); } }
/// <summary> /// Generates a unique session GUID for the user /// </summary> /// <returns>A unique GUID</returns> public async Task <ApiResponse <Guid> > GenerateSessionGuidAsync() { using (var db = new CalculatorDbContext()) { var sessionId = Guid.NewGuid(); var sessionData = new SessionData { ButtonsPushed = 0, SessionId = sessionId }; db.Add(sessionData); await db.SaveChangesAsync(); return(new ApiResponse <Guid> { Data = sessionId, IsSuccess = true, Message = "Session ID generated" }); } }
public async Task Save() { await _calculatorDbContext.SaveChangesAsync(); }