public async Task ProductDepositRequestVerifyConditionAsync(VerifyDto dto) { if (dto.Verify.HasValue && dto.Verify.Value) { var entityDto = await genericProductDepositRequestService.GetByIdAsync <ProductDepositRequestDto>(dto.Id); var walletDto = await genericWalletService.GetByUserIdAsync <WalletDto>(entityDto.CreatedUserId); var productItem = await productItemService.GetByProductIdWithWalletIdAsync(walletDto.Id, entityDto.ProductId); if (productItem == null) { productItem = await genericProductItemService.AddAsync(new ProductItemCreateDto() { CreatedUserId = entityDto.CreatedUserId, ProductId = entityDto.ProductId, WalletId = walletDto.Id, Amount = entityDto.Amount }); } else { productItem.Amount += entityDto.Amount; productItem.UpdateUserId = dto.UpdateUserId; var updateDto = mapper.Map <ProductItemUpdateDto>(productItem); await genericProductItemService.UpdateAsync(updateDto); } await genericProductItemService.Commit(); } }
//[ApiExplorerSettings(IgnoreApi= true)] public async Task <IActionResult> Post([FromForm] IFormFile Image, [FromRoute] string name) { Guid userId = Guid.Parse(sharedIdentityService.GetUserId); ProductCreateDto productCreateDto = new() { Image = Image, Name = name }; productCreateDto.CreatedUserId = userId; var imageUploadResponse = await imageService.UploadImageAsync(productCreateDto.Image); if (!imageUploadResponse.IsSuccessful) { logger.LogResponse(imageUploadResponse, "Ürün resmi yükleme başarısız"); return(CreateResponseInstance(imageUploadResponse)); } productCreateDto.ImageName = imageUploadResponse.Data; Product result = await productGenericService.AddAsync(productCreateDto); await productGenericService.Commit(); Response <ProductDto> response = Response <ProductDto> .Success(mapper.Map <ProductDto>(result), StatusCodes.Status201Created); logger.LogInformation($"api/product/addproduct calling enpoint"); logger.LogInformation($" adding product name='${productCreateDto.Name}'"); return(CreateResponseInstance(response)); }
public async Task <IActionResult> WebsiteAdd(WebsiteAddDto websiteAddDto) { if (ModelState.IsValid) { Website website = mapper.Map <Website>(websiteAddDto); UploadModel uploadResult = await fileHelper.UploadImage(websiteAddDto.Icon, folderInfo.WebsiteIcons); if (uploadResult.UploadState == UploadState.Success) { website.IconName = uploadResult.NewName; } else { ModelState.AddModelError("", uploadResult.ErrorMessage); return(View(websiteAddDto)); } website.CreateUserId = appUserSessionService.Get().Id; await websiteService.AddAsync(website); logger.LogInformation($"{ website.CreateUserId} id li kullanici yeni bir website olusturdu"); return(RedirectToAction("WebsiteAdd")); } else { ModelState.AddModelError("", "Lütfen gerekli tüm alanları doldurun."); return(View(websiteAddDto)); } }
private static async Task UserAddRole(IUserRoleService UserRoleService, IGenericService <UserRole> userRoleService, AppUser appUser, AppRole appRole) { if (!await UserRoleService.CheckUserRole(appUser.Id, appRole.Id)) { await userRoleService.AddAsync(new UserRole() { AppRoleId = appRole.Id, AppUserId = appUser.Id }); } }
public async Task <IActionResult> Post(T entity) { var result = await _baseService.AddAsync(entity); if (result > 0) { return(StatusCode(StatusCodes.Status201Created)); } else { return(NoContent()); } }
public async Task <ActionResult <T> > Post([FromBody] T value) { if (value == null) { return(BadRequest()); } var result = await _genericService.AddAsync(value); if (result == null) { return(NotFound()); } return(Ok(result)); }
private static async Task <AppRole> CheckRole(IAppRoleService appRoleService, IGenericService <AppRole> roleService, string roleName) { AppRole role = await appRoleService.FindByName(roleName); if (role == null) { role = new AppRole() { Name = roleName }; await roleService.AddAsync(role); } return(role); }
public async Task <IActionResult> ProductAdd(ProductAddDto model) { if (ModelState.IsValid) { Product product = mapper.Map <Product>(model); product.CreateUserId = appUserSessionService.Get().Id; await productService.AddAsync(product); return(RedirectToAction("ProductList")); } else { ModelState.AddModelError("", "Lütfen gerekli tüm alanları doldurun."); return(View(model)); } }
public async Task <IActionResult> TrackingRecordAdd(TrackingRecordAddDto model) { if (ModelState.IsValid) { TrackingRecord trackingRecord = mapper.Map <TrackingRecord>(model); trackingRecord.CreateUserId = appUserSessionService.Get().Id; await trackingRecordGenericService.AddAsync(trackingRecord); return(RedirectToAction("TrackingRecordList", new { productId = model.ProductId })); } else { ModelState.AddModelError("", "Lütfen gerekli tüm alanları doldurun."); return(View(model)); } }
private static async Task <AppUser> CheckUser(IAppUserService appUserService, IGenericService <AppUser> userService, AppUserAddDto appUserAddDto) { AppUser user = await appUserService.FindByUserName(appUserAddDto.UserName); if (user == null) { user = new AppUser() { UserName = appUserAddDto.UserName, FullName = appUserAddDto.FullName, Password = appUserAddDto.Password }; await userService.AddAsync(user); } return(user); }
public async Task <IActionResult> Add(UserResource resource) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } resource.PassWord = PasswordUtils.CreateMD5(resource.PassWord); User user = _mapper.Map <UserResource, User>(resource); ObjectResponse <User> response = await _userService.AddAsync(user); if (response.Success) { return(Ok(response.Object)); } return(BadRequest(response.Message)); }
public async Task <IActionResult> CreateWallet() { Response <NoContent> response = null; var userId = Guid.Parse(sharedIdentityService.GetUserId); var isExist = await walletService.WalletIsExistByUserIdAsync(userId); if (!isExist) { WalletCreateDto createWallet = new() { CreatedUserId = userId, UserId = userId }; var wallet = await walletGenericService.AddAsync(createWallet); await walletGenericService.Commit(); if (wallet is null) { response = Response <NoContent> .Fail( statusCode : StatusCodes.Status500InternalServerError, isShow : false, path : "api/wallet/cratewallet", errors : "Cüzdan oluşturulurken bir hata ile karşılaşıldı" ); logger.LogResponse(response, "Cüzdan oluşturulamadı."); return(CreateResponseInstance(response)); } } response = Response <NoContent> .Success(StatusCodes.Status201Created); logger.LogResponse(response, "Cüzdan başarıyla oluşturuldu/getirildi."); return(CreateResponseInstance(response)); } }
public async Task <IActionResult> SignUp(AppUserAddFormDto appUserAddDto) { if (ModelState.IsValid) { AppUser appUser = await appUserService.FindByUserName(appUserAddDto.UserName); if (appUser != null) { logger.LogInformation($"{appUser.UserName} Kullanici adi zaten alınmış"); ModelState.AddModelError("", $"{appUser.UserName} kullanıcı adı zaten alınmış"); return(View(appUserAddDto)); } appUserAddDto.Password = ToPasswordRepository.PasswordCryptographyCombine(appUserAddDto.Password); appUser = mapper.Map <AppUser>(appUserAddDto); await userService.AddAsync(appUser); logger.LogInformation($"{appUser.UserName} Kullanici olusturuldu"); AppRole memberRole = await appRoleService.FindByName(RoleInfo.Member); await userRoleService.AddAsync(new UserRole() { AppRoleId = memberRole.Id, AppUserId = appUser.Id }); logger.LogInformation($"{appUser.UserName} Kullanicisina varsayilan rol bilgisi eklendi"); return(RedirectToAction("SignIn")); } else { logger.LogInformation("AppUserAddDto Not Valid"); ModelState.AddModelError("", "Lütfen gereken tüm alanları doldurunuz."); return(View(appUserAddDto)); } }
public async Task <IActionResult> Post(GenaralCreateDto model) { Guid userId = Guid.Parse(sharedIdentityService.GetUserId); model.UserId = userId; Response <NoContent> response; try { IDTO dto = model.RequestType switch { RequestType.Deposit => mapper.Map <CreateDepositRequest>(model), RequestType.Product => mapper.Map <CreateProductDepositRequest>(model), RequestType.NewType => mapper.Map <CreateNewTypeRequest>(model), _ => throw new CustomException() }; IEntityBase entity = null; switch (model.RequestType) { case RequestType.Deposit: entity = await genericDepositRequestService.AddAsync(dto); entity.CreatedUserId = userId; await genericDepositRequestService.Commit(); break; case RequestType.Product: entity = await genericProductRequestService.AddAsync(dto); entity.CreatedUserId = userId; await genericProductRequestService.Commit(); break; case RequestType.NewType: entity = await genericNewTypeRequestService.AddAsync(dto); entity.CreatedUserId = userId; await genericNewTypeRequestService.Commit(); break; default: throw new CustomException(); } response = Response <NoContent> .Success(StatusCodes.Status201Created); logger.LogResponse(response, "Request başarıyla oluşturuldu ve eklendi."); } catch { response = Response <NoContent> .Fail( statusCode : StatusCodes.Status400BadRequest, isShow : true, path : "[POST] api/request", errors : "Desteklenmeyen istek tipi" ); logger.LogResponse(response, "Desteklenmeyen istek tipi."); } return(CreateResponseInstance(response)); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await Task.Delay(5000, stoppingToken); while (!stoppingToken.IsCancellationRequested) { if (ScannerServiceState.IsScanned) { var limitOptionRequests = (await limitOptionRequestGenericRepository.GetAllAsync()).Where(x => x.InProgress && !x.IsDeleted).ToList(); var marketItems = (await genericMarketItemRepository.GetAllAsync()).Where(x => x.InProgress && !x.IsDeleted).ToList(); foreach (var marketItem in marketItems) { var requests = limitOptionRequests.Where(x => x.ProductId == marketItem.ProductId && x.UnitPrice == marketItem.UnitPrice).OrderBy(x => x.CreatedTime).ToList(); foreach (var request in requests) { if (!marketItem.InProgress) { break; } request.Wallet = await walletGenericRepository.GetByIdAsync(request.WalletId); double satinalinabilecekitemsayisi = request.Wallet.Money / (marketItem.UnitPrice * (1 + ComissionRate)); double satinalinacaksayisi = 0; if (request.Amount <= satinalinabilecekitemsayisi) { if (request.Amount >= marketItem.Amount) { satinalinacaksayisi = marketItem.Amount; } else { satinalinacaksayisi = request.Amount; } } else { satinalinacaksayisi = satinalinabilecekitemsayisi; } //Limit islemina aktarilan para ve adet sistemi guncellendi request.Money -= satinalinacaksayisi * (marketItem.UnitPrice * (1 + ComissionRate)); request.Amount -= satinalinacaksayisi; request.UpdateUserId = Guid.Parse(UserStringInfo.SystemUserId); if (request.Amount == 0) { request.InProgress = false; } await limitOptionRequestGenericRepository.UpdateAsync(request); await limitOptionRequestGenericRepository.Commit(); //satan kullaniciya parayi ver WalletUpdateDto sellerWallet = await genericWalletService.GetByIdAsync <WalletUpdateDto>(marketItem.WalletId); sellerWallet.Money += satinalinacaksayisi * marketItem.UnitPrice; sellerWallet.UpdateUserId = Guid.Parse(UserStringInfo.SystemUserId); await genericWalletService.UpdateAsync(sellerWallet); //Accounting UPDATE WalletUpdateDto accountingWallet = await genericWalletService.GetByIdAsync <WalletUpdateDto>(AccountingState.AccountingWalletId); accountingWallet.Money += satinalinacaksayisi * marketItem.UnitPrice * ComissionRate; accountingWallet.UpdateUserId = Guid.Parse(UserStringInfo.SystemUserId); await genericWalletService.UpdateAsync(accountingWallet); await genericWalletService.Commit(); //kullanicinin hesabindaki urun adedini guncelle var productItem = await productItemService.GetAsync(request.WalletId, request.ProductId); productItem.Amount += satinalinacaksayisi; productItem.UpdateUserId = Guid.Parse(UserStringInfo.SystemUserId); await genericProductItemRepository.UpdateAsync(productItem); await genericProductItemRepository.Commit(); //marketItem urun adedini guncelle marketItem.Amount -= satinalinacaksayisi; if (marketItem.Amount == 0) { marketItem.InProgress = false; } MarketItemUpdateDto marketItemUpdateDto = mapper.Map <MarketItemUpdateDto>(marketItem); marketItemUpdateDto.UpdateUserId = Guid.Parse(UserStringInfo.SystemUserId); await genericMarketItemService.UpdateAsync(marketItemUpdateDto); await genericMarketItemService.Commit(); //islem gecmisi olustur TransactionCreateDto transaction = new() { Amount = satinalinacaksayisi, CreatedUserId = Guid.Parse(UserStringInfo.SystemUserId), ProductId = request.ProductId, UnitPrice = marketItem.UnitPrice, WalletIdBuyer = request.WalletId, WalletIdSeller = sellerWallet.Id }; await genericTransactionService.AddAsync(transaction); await genericTransactionService.Commit(); genericTransactionService.BeginTransaction(); genericMarketItemService.BeginTransaction(); genericProductItemRepository.BeginTransaction(); genericWalletService.BeginTransaction(); limitOptionRequestGenericRepository.BeginTransaction(); } } ScannerServiceState.IsScanned = false; } } } }
public async Task <IActionResult> AddLike(ArticleLikeDto like) { return(ActionResultInstance(await _likeService.AddAsync(like))); }
public async Task <IActionResult> Save(ProductDto productDto) { return(ActionResultInstance(await _productService.AddAsync(productDto))); }
public async Task <Response <NoContent> > BuyAsync(BuyModel buyModel) { Response <NoContent> response = null; DTO.Product.ProductTradeDto productTradeDto = await productService.GetProductByIdAsync(buyModel.ProductId); if (productTradeDto.Amount < buyModel.Amount) { response = Response <NoContent> .Fail( statusCode : StatusCodes.Status400BadRequest, isShow : true, path : "[post] api/trade", errors : "Piyasada bu miktarda ürün bulunmamaktadır" ); return(response); } List <MarketItemDto> marketItems = productTradeDto.MarketItems.Where(x => x.WalletId != buyModel.WalletId).OrderBy(x => x.UnitPrice).ToList(); double count = 0; if (marketItems != null && marketItems.Any()) { foreach (MarketItemDto marketItem in marketItems) { if (count == buyModel.Amount) { break; } double buyToCount = buyModel.Amount - count; double satinalinabilecekitemsayisi = buyModel.WalletDto.Money / (marketItem.UnitPrice * (1 + ComissionRate)); double satinalinacaksayisi = 0; if (buyToCount <= satinalinabilecekitemsayisi) { if (buyToCount >= marketItem.Amount) { satinalinacaksayisi = marketItem.Amount; } else if (marketItem.Amount > buyToCount) { satinalinacaksayisi = buyToCount; } } else { satinalinacaksayisi = satinalinabilecekitemsayisi; } try { count += satinalinacaksayisi; //Kullanicinin hesabindan satin alinacak urunun parasini dus buyModel.WalletDto.Money -= satinalinacaksayisi * (marketItem.UnitPrice * (1 + ComissionRate)); await genericWalletService.UpdateAsync(new WalletUpdateDto() { Id = buyModel.WalletDto.Id, Money = buyModel.WalletDto.Money, UpdateUserId = Guid.Parse(UserStringInfo.SystemUserId) }); //satan kullaniciya parayi ver WalletUpdateDto sellerWallet = await genericWalletService.GetByIdAsync <WalletUpdateDto>(marketItem.WalletId); sellerWallet.Money += satinalinacaksayisi * marketItem.UnitPrice; sellerWallet.UpdateUserId = Guid.Parse(UserStringInfo.SystemUserId); await genericWalletService.UpdateAsync(sellerWallet); //Accounting UPDATE WalletUpdateDto accountingWallet = await genericWalletService.GetByIdAsync <WalletUpdateDto>(AccountingState.AccountingWalletId); accountingWallet.Money += satinalinacaksayisi * marketItem.UnitPrice * ComissionRate; accountingWallet.UpdateUserId = Guid.Parse(UserStringInfo.SystemUserId); await genericWalletService.UpdateAsync(accountingWallet); await genericWalletService.Commit(); //kullanicinin hesabindaki urun adedini guncelle buyModel.ProductItem.Amount += satinalinacaksayisi; buyModel.ProductItem.UpdateUserId = Guid.Parse(UserStringInfo.SystemUserId); await genericProductItemRepository.UpdateAsync(buyModel.ProductItem); await genericProductItemRepository.Commit(); //marketItem urun adedini guncelle marketItem.Amount -= satinalinacaksayisi; if (marketItem.Amount == 0) { marketItem.InProgress = false; } MarketItemUpdateDto marketItemUpdateDto = mapper.Map <MarketItemUpdateDto>(marketItem); marketItemUpdateDto.UpdateUserId = Guid.Parse(UserStringInfo.SystemUserId); await genericMarketItemService.UpdateAsync(marketItemUpdateDto); await genericMarketItemService.Commit(); //islem gecmisi olustur TransactionCreateDto transaction = new() { Amount = satinalinacaksayisi, CreatedUserId = Guid.Parse(UserStringInfo.SystemUserId), ProductId = buyModel.ProductId, UnitPrice = marketItem.UnitPrice, WalletIdBuyer = buyModel.WalletId, WalletIdSeller = sellerWallet.Id }; await genericTransactionService.AddAsync(transaction); await genericTransactionService.Commit(); response = Response <NoContent> .Success(StatusCodes.Status201Created); } catch { await genericWalletService.Commit(false); await genericProductItemRepository.Commit(false); await genericMarketItemService.Commit(false); await genericTransactionService.Commit(false); response = Response <NoContent> .Fail( statusCode : StatusCodes.Status500InternalServerError, isShow : true, path : "[post] api/trade", errors : "Satin alim gerceklesirken bir hata meydana geldi" ); } } } if (response == null) { response = Response <NoContent> .Success(StatusCodes.Status201Created); } return(response); }
public async Task <int> AddAsync(Route entity) { return(await _context.AddAsync(entity)); }
public async Task <IActionResult> CreateProduct(ProductDto productDto) { var resultProductDto = await _productService.AddAsync(productDto); return(ActionResultInstance <ProductDto>(resultProductDto)); }