public DeleteAccountResultDTO DeleteAccount(DeleteAccountInDTO dto) { DeleteAccountResultDTO result = new DeleteAccountResultDTO(); using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <Account> accountRepository = uow.GetRepository <Account>(); Account acc = accountRepository.GetAll(x => x.Id == dto.AccountId && x.CustomerId == dto.CustomerId && x.Status == 1).FirstOrDefault(); if (acc == null) { result.IsSuccess = false; result.ResponseMessage = "Geçersiz bir işlem yürütüldü. Lütfen bilgileri kontrol ederek tekrar deneyiniz."; } else { acc.Status = 0; accountRepository.Update(acc); uow.SaveChanges(); result.IsSuccess = true; result.ResponseMessage = "Hesap başarıyla silindi."; } return(result); } }
public BaseBUsiness() { if (baseUnitOfWork == null) { baseUnitOfWork = new BaseUnitOfWork <T>(); } }
private void DeleteCustomer(IList <Customer> customers) { using (var uow = new BaseUnitOfWork <FixMyCarEntities>()) { using (var repo = new BaseRepository <Customer>(uow)) { repo.Delete(customers); } uow.Save(); } }
public void AddOrUpdateCustomer(Customer customer) { using (var uow = new BaseUnitOfWork<FixMyCarEntities>()) { using (var repo = new BaseRepository<Customer>(uow)) { repo.AddOrUpdate(customer); } uow.Save(); newCustId = customer.CustomerId; } }
public void AddOrUpdateCustomer(Customer customer) { using (var uow = new BaseUnitOfWork <FixMyCarEntities>()) { using (var repo = new BaseRepository <Customer>(uow)) { repo.AddOrUpdate(customer); } uow.Save(); newCustId = customer.CustomerId; } }
public Customer CookieControl(LoginDTO dto) { Customer customer = null; using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <Customer> customerRepository = uow.GetRepository <Customer>(); customer = customerRepository.GetAll(x => x.SecretKey == dto.SecretKey && x.TCKN == dto.TCKN && x.Status == 1).FirstOrDefault(); return(customer); } }
public HGSCard GetHGSCardById(int Id, int customerId) { HGSCard card = new HGSCard(); using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <HGSCard> cardRepository = uow.GetRepository <HGSCard>(); card = cardRepository.GetAll(x => x.Id == Id && x.CustomerId == customerId && x.Status == 1).FirstOrDefault(); return(card); } }
public List <HGSCard> GetHGSCardList(int customerId) { List <HGSCard> cards = new List <HGSCard>(); using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <HGSCard> cardRepository = uow.GetRepository <HGSCard>(); cards = cardRepository.GetAll(x => x.CustomerId == customerId && x.Status == 1).ToList(); return(cards); } }
public List <Account> GetAllAccounts(int customerId) { List <Account> accounts = new List <Account>(); using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <Account> accountRepository = uow.GetRepository <Account>(); accounts = accountRepository.GetAll(x => x.CustomerId == customerId && x.Status == 1).ToList(); return(accounts); } }
public Customer LoginControl(LoginDTO dto) { Customer customer = null; using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <Customer> customerRepository = uow.GetRepository <Customer>(); string encryptedPass = CryptoService.ConvertToMD5(dto.Password); customer = customerRepository.GetAll(x => x.Password == encryptedPass && x.TCKN == dto.TCKN && x.Status == 1).FirstOrDefault(); return(customer); } }
public TransferOutDTO GetTransferDTO(int accountId) { TransferOutDTO dto = new TransferOutDTO(); using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <Account> accountRepository = uow.GetRepository <Account>(); dto.Account = accountRepository.GetAll(x => x.Id == accountId && x.Status == 1).FirstOrDefault(); return(dto); } }
public VirmanOutDTO GetVirmanDTO(int customerId, int accountId) { VirmanOutDTO dto = new VirmanOutDTO(); using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <Account> accountRepository = uow.GetRepository <Account>(); dto.Account = accountRepository.GetAll(x => x.Id == accountId && x.Status == 1).FirstOrDefault(); dto.AccountList = accountRepository.GetAll(x => x.CustomerId == customerId && x.Status == 1 && x.Id != accountId).ToList(); return(dto); } }
public TransferResultDTO TransferTransaction(TransferInDTO dto) { TransferResultDTO result = new TransferResultDTO(); using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <Account> accountRepository = uow.GetRepository <Account>(); IRepository <Customer> customerRepository = uow.GetRepository <Customer>(); var fromAccount = accountRepository.GetAll(x => x.Id == dto.FromAccountId && x.CustomerId == dto.CustomerId && x.Status == 1).FirstOrDefault(); var accountNo = dto.ToAccountNo.Substring(0, 4); var accountIntNo = Convert.ToInt32(accountNo); var customerNo = dto.ToAccountNo.Substring(4, 5); var customerIntNo = Convert.ToInt32(customerNo); var toCustomer = customerRepository.GetAll(x => x.CustomerNo == customerIntNo && x.Status == 1).FirstOrDefault(); var toAccount = accountRepository.GetAll(x => x.AccountNo == accountIntNo && x.CustomerId == toCustomer.Id && x.Status == 1).FirstOrDefault(); if (fromAccount == null || toAccount == null) { result.IsSuccess = false; result.ResponseMessage = "Geçersiz bir işlem yürütüldü. Girdiğiniz bilgileri kontrol ediniz."; } else if (fromAccount.Balance < dto.FromBalance) { result.IsSuccess = false; result.ResponseMessage = "Hesabınızda yeteri kadar bakiye bulunmamaktadır."; } else if (fromAccount.CustomerId != dto.CustomerId) { result.IsSuccess = false; result.ResponseMessage = "Fraud işlem algılandı. İşlem iptal edildi."; } else { fromAccount.Balance -= dto.FromBalance; toAccount.Balance += dto.FromBalance; uow.SaveChanges(); result.IsSuccess = true; result.ResponseMessage = "Transfer başarıyla gerçekleştirildi."; } return(result); } }
public bool NewCustomer(Customer customer) { bool result = false; using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <Customer> customerRepository = uow.GetRepository <Customer>(); string encryptedPass = CryptoService.ConvertToMD5(customer.Password); Customer _customer = customerRepository.GetAll(x => x.TCKN == customer.TCKN && x.Status == 1).FirstOrDefault(); if (_customer != null) { result = false; } else { int acc = customerRepository.GetAll().Max(x => x.CustomerNo); if (acc == 0) { acc = 20001; } else { acc += 1; } Guid secret = Guid.NewGuid(); customerRepository.Add(new Customer() { Address = customer.Address, CreateDate = DateTime.Now, Firstname = customer.Firstname, Lastname = customer.Lastname, Password = encryptedPass, Phone = customer.Phone, SecretKey = secret, Status = 1, TCKN = customer.TCKN, CustomerNo = acc }); uow.SaveChanges(); result = true; } } return(result); }
public decimal GetAccountBalance(int accountId) { decimal balance = 0; using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <Account> accountRepository = uow.GetRepository <Account>(); Account acc = accountRepository.GetAll(x => x.Id == accountId && x.Status == 1).FirstOrDefault(); if (acc != null) { balance = (decimal)acc.Balance; } return(balance); } }
public NewAccountResultDTO NewAccount(NewAccountInDTO inDto) { NewAccountResultDTO dto = new NewAccountResultDTO(); using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <Account> accountRepository = uow.GetRepository <Account>(); var acc = accountRepository.GetAll(x => x.CustomerId == inDto.CustomerId).ToList(); short newAcc; if (acc.Any()) { newAcc = Convert.ToInt16(acc.Max(x => x.AccountNo) + 1); } else { newAcc = 1001; } accountRepository.Add(new Account() { AccountNo = newAcc, Balance = inDto.Balance, CreateDate = DateTime.Now, Status = 1, CustomerId = inDto.CustomerId }); int result = uow.SaveChanges(); if (result > 0) { dto.IsSuccess = true; dto.ResponseMessage = "Hesap başarıyla oluşturuldu."; } else { dto.IsSuccess = false; dto.ResponseMessage = "Geçersiz bir işlem yürütüldü. Lütfen bilgileri kontrol ederek tekrar deneyiniz."; } return(dto); } }
public HGSBalanceQueryResultDTO HGSBalanceQuery(string cardNo) { HGSCard card = new HGSCard(); using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <HGSCard> cardRepository = uow.GetRepository <HGSCard>(); Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("CardNo", cardNo); string raw = HttpPostRequest($"/Payment/GetBalanceFromCardNo?CardNo={cardNo}", parameters, null); HGSBalanceQueryResultDTO dto = JsonConvert.DeserializeObject <HGSBalanceQueryResultDTO>(raw); card = cardRepository.GetAll(x => x.CardNo == cardNo && x.Status == 1).FirstOrDefault(); card.Balance = dto.Balance; card.ModifyDate = DateTime.Now; uow.SaveChanges(); return(dto); } }
public HGSPaymentResultDTO HGSPayment(HGSPaymentInDTO payment) { HGSPaymentResultDTO result = new HGSPaymentResultDTO(); using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <HGSCard> cardRepository = uow.GetRepository <HGSCard>(); IRepository <Account> accountRepository = uow.GetRepository <Account>(); HGSCard card = cardRepository.GetAll(x => x.Id == payment.CardId && x.Status == 1).FirstOrDefault(); Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("CardNo", card.CardNo); parameters.Add("PaymentPrice", payment.Balance.ToString()); parameters.Add("PaymentType", payment.PaymentType.ToString()); parameters.Add("PaymentDate", payment.CreateDate.ToString()); string raw = HttpPostRequest($"/Payment/DepositHGSCard", parameters, null); HGSResultDTO resultDTO = JsonConvert.DeserializeObject <HGSResultDTO>(raw); if (resultDTO.IsSuccess) { card.Balance += payment.Balance; card.ModifyDate = DateTime.Now; Account acc = accountRepository.GetAll(x => x.Id == payment.AccountId && x.Status == 1).FirstOrDefault(); HGSCardTypeDTO cardType = GetCardTypes(); acc.Balance -= payment.Balance; uow.SaveChanges(); } result.IsSuccess = true; result.ResponseMessage = resultDTO.Message; return(result); } }
public UnitOfWork(string profileName) { _baseUow = new BaseUnitOfWork <T>(profileName); }
public UnitOfWork() { _baseUow = new BaseUnitOfWork <T>(); }
public NewHGSCardResultDTO NewHGSCard(NewHGSCardInDTO card) { NewHGSCardResultDTO result = new NewHGSCardResultDTO(); using (BaseContext context = ContextFactory.Create()) { IUnitOfWork uow = new BaseUnitOfWork(context); IRepository <Customer> customerRepository = uow.GetRepository <Customer>(); IRepository <HGSCard> cardRepository = uow.GetRepository <HGSCard>(); IRepository <Account> accountRepository = uow.GetRepository <Account>(); Customer cus = customerRepository.GetAll(x => x.Id == card.CustomerId && x.Status == 1).FirstOrDefault(); Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("TCKN", cus.TCKN); parameters.Add("VehiclePlate", card.VehiclePlate); parameters.Add("VehicleType", card.VehicleType.ToString()); parameters.Add("PaymentPrice", card.Balance.ToString()); parameters.Add("PaymentType", card.PaymentType.ToString()); parameters.Add("RequestDate", card.RequestDate.ToString()); string raw = HttpPostRequest($"/Payment/BuyNewHGSCard", parameters, null); result = JsonConvert.DeserializeObject <NewHGSCardResultDTO>(raw); if (result.IsSuccess) { HGSCard newCard = new HGSCard(); newCard.Balance = card.Balance; newCard.CardNo = result.Data.CardNo; newCard.ModifyDate = DateTime.Now; newCard.CreateDate = result.Data.CreateDate; newCard.CustomerId = cus.Id; newCard.Status = 1; newCard.VehiclePlate = card.VehiclePlate; newCard.VehicleType = card.VehicleType; cardRepository.Add(newCard); Account acc = accountRepository.GetAll(x => x.Id == card.AccountId && x.Status == 1).FirstOrDefault(); HGSCardTypeDTO cardType = GetCardTypes(); decimal totalPayment = card.Balance; switch (card.VehicleType) { case 1: totalPayment += cardType.CardPriceA; break; case 2: totalPayment += cardType.CardPriceB; break; case 3: totalPayment += cardType.CardPriceC; break; default: break; } acc.Balance -= totalPayment; uow.SaveChanges(); } return(result); } }
public MongoRepository(BaseUnitOfWork unitOfWork, MongoShoppingBeesContext mongoContext) : base(unitOfWork) { ContractUtility.Requires <ArgumentNullException>(unitOfWork != null, "unitOfWork instance cannot be null"); ContractUtility.Requires <ArgumentNullException>(mongoContext != null, "esContext instance cannot be null"); _mongoCollection = mongoContext.GetMongoCollection <TEntity>(); }
private void DeleteCustomer(IList<Customer> customers) { using (var uow = new BaseUnitOfWork<FixMyCarEntities>()) { using (var repo = new BaseRepository<Customer>(uow)) { repo.Delete(customers); } uow.Save(); } }