コード例 #1
0
        /// <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();
        }
コード例 #2
0
 public async Task <bool> CreateAsync(ServerFormula entity)
 {
     if (!Validator.Validate(entity))
     {
         return(false);
     }
     db.Formulas.Add(entity);
     return(await db.SaveChangesAsync() > 0);
 }
コード例 #3
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();
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
        /// <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"
                });
            }
        }
コード例 #7
0
 public async Task Save()
 {
     await _calculatorDbContext.SaveChangesAsync();
 }