public User AddUser(User user) { _dbContext.Users.Add(user); var result = _dbContext.SaveChanges(); return(user); }
private ProceedStatus InnerAfter3ds(Session session, Operation3ds operation3ds, OperationType operationType, Submit3Ds submit3Ds) { var lastOperation = _dbContext.Operation.Include(x => x.Terminal).OrderByDescending(x => x.Id).First(x => x.SessionId == session.Id); if (lastOperation.Id != operation3ds.OperationId) { return new ProceedStatus { OperationStatus = OperationStatus.Error } } ; var processing = _processingFactory.GetProcessing(lastOperation.TerminalId, _dbContext); ProceedStatus response; PaymentData paymentData = null; if (operation3ds.SaveCredentials) { paymentData = _remoteContainer.Get(operation3ds.LocalMd); } try { var processingResponse = processing.Process3Ds(session, lastOperation, lastOperation.Terminal, paymentData, submit3Ds); lastOperation.OperationStatus = processingResponse.Status; switch (processingResponse.Status) { case OperationStatus.Success: lastOperation.InvolvedAmount = lastOperation.Amount; break; } response = new ProceedStatus { OperationStatus = lastOperation.OperationStatus }; } catch (Exception exc) { _logger.LogError(exc.Message); lastOperation.OperationStatus = OperationStatus.Error; response = new ProceedStatus { OperationStatus = OperationStatus.Error }; } finally { _dbContext.SaveChanges(); } return(response); }
public async Task JoinPlatformAsync(int sellerId, int platformId) { if (await _context .Sellers .AnyAsync(s => s.Id == sellerId && s.PlatformSellers.Any(x => x.PlatformId == platformId))) { return; //already joined } _context.Set <PlatformSeller>().Add(new PlatformSeller { PlatformId = platformId, SellerId = sellerId }); _context.SaveChanges(); }
private static void SeedData(PaymentSystemContext context) { try { //get data from json file and seed data in DB for test. var file = File.ReadAllText("DummyData/DummyData.json"); var dummyData = JsonConvert.DeserializeObject <IEnumerable <Account> >(file); context.AddRange(dummyData); context.SaveChanges(); } catch (Exception) { //not adding any data to DB if exceptions return; } }
public ContentResult Pay(string Id, [FromServices] SessionManagerService sessionManager, [FromServices] OperationManagerService operationManager, [FromServices] FormManagerService formManager, [FromServices] PaymentSystemContext dbContext, [FromServices] FormDataCryptService cryptService) { try { var session = sessionManager.Get(Id); if (session.SessionType != SessionType.OneStep && session.SessionType != SessionType.TwoStep) { return(base.Content(formManager.GetErrorForm())); } var result = operationManager.CheckPaymentPossibility(session); var dictionary = new Dictionary <string, string>(); switch (result) { case PaymentPossibility.LimitExceeded: case PaymentPossibility.SessionExpired: return(base.Content(formManager.GetErrorForm())); case PaymentPossibility.AlreadyPaid: return(base.Content(formManager.GetSuccessForm())); default: var generationTime = DateTime.UtcNow; session.LastFormGenerationTime = generationTime; session.TryCount++; dbContext.SaveChanges(); var formSign = new FormSign { GenerationTime = generationTime, SessionId = session.Id }; dictionary.Add("sessionId", session.ExternalId); dictionary.Add("code", cryptService.Crypt(formSign)); return(base.Content(formManager.GetPaymentForm(dictionary))); } } catch (Exception) { return(base.Content(formManager.GetErrorForm())); } }
public Session Create(Merchant merchant, SessionCreateRequest request) { try { if (_dbContext.Session.Any(x => x.MerchantId == merchant.Id && x.OrderId == request.OrderId)) { throw new OuterException(InnerError.SessionAlreadyExists); } var session = new Session { Amount = request.Amount, Currency = request.Currency, FormKey = request.FormKey, FormLanguage = request.FormLanguage, MerchantId = merchant.Id, OrderDescription = request.OrderDescription, OrderId = request.OrderId, ExternalId = IdHelper.GetSessionId(), ExpireTime = DateTime.UtcNow.AddMinutes(SessionMinutesToExpire), SessionType = request.SessionType, TryCount = 0 }; _dbContext.Session.Add(session); _dbContext.SaveChanges(); return(session); } catch (DbUpdateException) { throw new OuterException(InnerError.SessionAlreadyExists); } catch (Exception ex) { _logger.LogError($"Something went wrong Merchant-[{merchant.Id}] OrderId[{request.OrderId}]"); _logger.LogError(ex.Message); throw; } }
public virtual T Add(T entity) { _dbContext.Set <T>().Add(entity); _dbContext.SaveChanges(); return(entity); }