コード例 #1
0
        public AppointmentDTO GetAppointmentById(int id)
        {
            Appointment appointment;

            using (_appointments.BeginTransaction())
            {
                appointment = _appointments.FindById(id);
            }
            var mappingItem = Mapper.Map <Appointment, AppointmentDTO>(appointment);

            return(mappingItem);
        }
コード例 #2
0
ファイル: NotifyService.cs プロジェクト: DenisTasks/Test
        public IEnumerable <NotificationDTO> GetNotificationsByUserId(int id)
        {
            List <Notification> collection;

            using (_notifications.BeginTransaction())
            {
                collection = _notifications.Get(x => x.Users.Any(s => s.UserId == id)).ToList();
            }
            var mappingCollection = Mapper.Map <IEnumerable <Notification>, IEnumerable <NotificationDTO> >(collection).ToList();

            foreach (var item in mappingCollection)
            {
                item.Room = _locations.FindById(item.LocationId).Room;
            }
            return(mappingCollection);
        }
コード例 #3
0
        public ICollection <GroupDTO> GetGroupsWithNoAncestors()
        {
            List <Group> collection;

            using (_logs.BeginTransaction())
            {
                collection = _groups.Get(g => g.ParentId == null).ToList();
            }
            var mappingCollection = Mapper.Map <IEnumerable <Group>, ICollection <GroupDTO> >(collection).ToList();

            foreach (var item in mappingCollection)
            {
                item.CreatorName = GetUserById(item.CreatorId).Name;
                item.ParentName  = GetGroupName(item.ParentId);
                item.Groups      = GetGroupFirstGeneration(item.GroupId);
                item.Users       = new ObservableCollection <UserDTO>(GetGroupUsers(item.GroupId));
            }
            return(mappingCollection);
        }
コード例 #4
0
 public void ExecuteTemplate(IEntity entity)
 {
     try
     {
         repository.OpenConnection();
         repository.BeginTransaction();
         ExecuteOperation(entity);
         repository.Commit();
     }
     catch (Exception)
     {
         repository.Rollback();
         throw;
     }
     finally
     {
         repository.CloseConnection();
     }
 }
コード例 #5
0
        public UserDTO AuthenticateUser(string username, string password)
        {
            User user = _users.Get(u => u.UserName.Equals(username) && u.Password.Equals(EncryptionHelpers.HashPassword(password, u.Salt))).FirstOrDefault();

            if (user != null && user.IsActive)
            {
                using (var transaction = _users.BeginTransaction())
                {
                    user          = _users.FindById(user.UserId);
                    user.Salt     = EncryptionHelpers.GenerateSalt();
                    user.Password = EncryptionHelpers.HashPassword(password, user.Salt);
                    _users.Save();
                    transaction.Commit();
                }
                return(Mapper.Map <User, UserDTO>(user));
            }
            else
            {
                throw new UnauthorizedAccessException("Wrong credentials.");
            }
        }
コード例 #6
0
        public async Task <UserResponse> Registration(RegistrationRequest model)
        {
            using (var transaction = _repository.BeginTransaction())
            {
                try
                {
                    User entity = new User()
                    {
                        LastName     = model.LastName,
                        FirstName    = model.FirstName,
                        Login        = model.Login,
                        Email        = model.Email,
                        PasswordHash = GetHashedPassword(model.Password),
                        Role         = RoleEnumHepler.GetDefaultRole()
                    };

                    await _repository.CreateAsync(entity);

                    var identity   = GetIdentity(entity);
                    var encodedJwt = GenerateToken(identity);

                    transaction.Commit();

                    return(new UserResponse()
                    {
                        Id = entity.Id,
                        Login = entity.Login,
                        Role = entity.Role,
                        Token = encodedJwt
                    });
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
        }
コード例 #7
0
ファイル: LogService.cs プロジェクト: DenisTasks/Test
 public void LogAppointment(AppointmentDTO appointment, int id, bool action)
 {
     using (var transaction = _logs.BeginTransaction())
     {
         try
         {
             _logs.Create(new Log
             {
                 AppointmentName = appointment.Subject,
                 ActionAuthorId  = id,
                 CreatorId       = id,
                 Action          = action ? "Added" : "Removed",
                 EventTime       = DateTime.Now
             });
             _logs.Save();
             transaction.Commit();
         }
         catch (Exception e)
         {
             transaction.Rollback();
             throw new Exception(e + " from BLL");
         }
     }
 }
        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;
                }
            }
        }
    }
コード例 #9
0
 public void BeginTransaction()
 {
     genericRepository.BeginTransaction();
 }
コード例 #10
0
 public void BeginTransaction()
 {
     _oRepository.BeginTransaction();
 }