public void GroupOperation(OperationDto operationDto)
        {
            Operation operation = _operationRepository.Get(operationDto.Id);

            operation.PermissionId = operationDto.PermissionId;
            _operationRepository.Update(operation);
        }
Exemple #2
0
        /// <summary>
        /// 操作授权验证
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static AuthorizeResult CheckAuthorization(AuthorizationFilterContext context)
        {
            if (context == null)
            {
                return(AuthorizeResult.ChallengeResult());
            }

            #region 操作信息

            string       controllerName = context.RouteData.Values["controller"].ToString();
            string       actionName     = context.RouteData.Values["action"].ToString();
            string       methodName     = context.HttpContext.Request.Method;
            OperationDto operation      = new OperationDto()
            {
                ControllerCode = controllerName,
                ActionCode     = actionName
            };

            #endregion

            //登陆用户
            var loginUser = IdentityManager.GetLoginUser();
            if (loginUser == null)
            {
                return(AuthorizeResult.ChallengeResult());
            }
            var allowAccess = CheckAuthorization(loginUser, operation);
            return(allowAccess ? AuthorizeResult.SuccessResult() : AuthorizeResult.ForbidResult());
        }
Exemple #3
0
        public OperationDto GetById(Guid?userId, int id)
        {
            OperationDto operation = null;

            try
            {
                using (var context = Factory.CreateContext(ConnexionString))
                {
                    var opRepo = Factory.GetOperationRepository(context);

                    Operation myOp = opRepo.GetById(id);
                    if (myOp != null)
                    {
                        BankAccount ba = ExtractBankAccount(userId, myOp.BankAccountId, context); // une exception est lancée si le bank account n'appartient pas à l'user
                        operation = myOp.ToDto();
                    }
                }
            }
            catch (DaGetServiceException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new DaGetServiceException(
                          String.Format("Erreur lors de la récupération de l'opération d'id {0} par l'utilisateur {0}", id, userId), ex);
            }

            return(operation);
        }
Exemple #4
0
        public static OperationDto ConvertToViewModel(this Operation operation)
        {
            var vm = new OperationDto
            {
                Deleted                      = operation?.IsDeleted ?? false,
                Active                       = operation?.Active ?? false,
                ActiveFrom                   = operation?.ActiveFrom ?? DateTime.MinValue,
                ActiveTo                     = operation?.ActiveFrom ?? DateTime.MinValue,
                CreatedBy                    = operation?.CreatedById ?? "",
                DeletedBy                    = operation?.DeletedById ?? "",
                ModifiedBy                   = operation?.ModifiedById ?? "",
                DateCreated                  = operation?.CreatedDate ?? DateTime.MinValue,
                DateModified                 = operation?.ModifiedDate ?? DateTime.MinValue,
                DateDeleted                  = operation?.DeletedDate ?? DateTime.MinValue,
                Description                  = operation?.Description ?? "",
                Id                           = operation?.Id,
                Name                         = operation.Name ?? "",
                UserMayViewCreatedProp       = true,
                UserMayViewDeletedProp       = true,
                UserMayViewLastModifieddProp = true,
                RowVersion                   = operation.RowVersion
            };

            return(vm);
        }
Exemple #5
0
        public async Task <IActionResult> Create([FromBody] OperationDto operationDto)
        {
            var @event = new OperationCreatedEvent(operationDto.Value, operationDto.OperationType);
            await _operationService.SendOperation(@event);

            return(Ok());
        }
        public async Task <(bool, OperationDto)> TrySetAsync(string id, string ownUserId, string name, OperationState state,
                                                             string code = null, string reason = null, string projectId = null, string issueId = null, string sprintId = null, string userId = null)
        {
            var operation = await GetAsync(id);

            if (operation is null)
            {
                operation = new OperationDto();
            }
            else if (operation.State == OperationState.Completed || operation.State == OperationState.Rejected)
            {
                return(false, operation);
            }

            operation.Id        = id;
            operation.OwnUserId = ownUserId ?? string.Empty;
            operation.Name      = name;
            operation.State     = state;
            operation.Code      = code ?? string.Empty;
            operation.Reason    = reason ?? string.Empty;
            operation.ProjectId = projectId ?? string.Empty;
            operation.IssueId   = issueId ?? string.Empty;
            operation.SprintId  = sprintId ?? string.Empty;
            operation.UserId    = userId ?? string.Empty;
            await _cache.SetStringAsync(GetKey(id),
                                        JsonConvert.SerializeObject(operation),
                                        new DistributedCacheEntryOptions
            {
                SlidingExpiration = TimeSpan.FromSeconds(_options.ExpirySeconds)
            });

            OperationUpdated?.Invoke(this, new OperationUpdatedEventArgs(operation));

            return(true, operation);
        }
Exemple #7
0
        private void BtnDeleteOperation_Click(object sender, RoutedEventArgs e)
        {
            OperationDto clickedOperation = GetClickedOperation(sender);

            _operationRepo.Delete(clickedOperation.Id);
            InitializeTransactions();
        }
Exemple #8
0
        public async Task <IActionResult> Post([FromBody] OperationDto operationDto)
        {
            var model = _mapper.Map <OperationDto, Operation>(operationDto);
            await _operationRepository.AddAsync(model);

            return(Ok(model));
        }
Exemple #9
0
        private OperationDto GetClickedOperation(object sender)
        {
            DependencyObject parent = ((Button)sender).Parent;

            while (!(parent is EditableTransactionControl))
            {
                parent = LogicalTreeHelper.GetParent(parent);
            }

            int opId = ((EditableTransactionControl)parent).IdOperation;

            OperationDto operationDto = _operationRepo.Get(opId);

            return(operationDto);

            ////get button parent until we reach the user control (Editable Transaction Control)
            //DependencyObject ucParent = ((Button)sender).Parent;
            //while (!(ucParent is UserControl))
            //{
            //    ucParent = LogicalTreeHelper.GetParent(ucParent);
            //}

            //// cast to specific type from UserControl
            //EditableTransactionControl userControl = (EditableTransactionControl)ucParent;

            ////Get from Db the account with the id of the UserControl
            //OperationDto operationDto = _operationRepo.Get(userControl.IdOperation);
            //return operationDto;
        }
        private OperationDto Map(OperationResult operationResult)
        {
            OperationDto dto;

            if (operationResult.Status == OperationStatus.Done)
            {
                dto = new OperationDto
                {
                    Status            = operationResult.Status.ToString(),
                    Amount            = operationResult.Result.Operation.Amount,
                    BalanceAfterApply = operationResult.Result.BalanceAfterApply,
                    AppliedDate       = operationResult.Result.AppliedDate,
                    Description       = operationResult.Result.ToString()
                };
            }
            else
            {
                dto = new OperationDto
                {
                    Status      = operationResult.Status.ToString(),
                    Description = operationResult.Comment
                };
            }
            return(dto);
        }
Exemple #11
0
        private void ValidateOperationWallet(OperationDto operationDto, List <Wallet> userWallets)
        {
            if (operationDto.WalletId == 0)
            {
                var walletCount = userWallets.Count;
                if (walletCount == 0)
                {
                    throw new WalletNotFoundException(ServiceMessages.CreateWalletFirst);
                }
                if (walletCount > 1)
                {
                    throw new WalletNotSpecifiedException(ServiceMessages.SpecifyWallet);
                }

                operationDto.WalletId = userWallets.First().WalletId;
            }
            else
            {
                if (userWallets.All(x => x.WalletId != operationDto.WalletId))
                {
                    throw new WalletNotFoundException(String
                                                      .Format(ServiceMessages.WalletNotFound, operationDto.WalletId));
                }
            }
        }
Exemple #12
0
 private void ValidateOperationDate(OperationDto operationDto)
 {
     if (operationDto.OperationDate == default)
     {
         operationDto.OperationDate = DateTime.Now;
     }
 }
Exemple #13
0
        public async Task <bool> UpdateOperation(OperationDto operationDto)
        {
            var item = _repoWorker.FindById(operationDto.WorkerID);

            item.Operation = operationDto.Operation;
            _repoWorker.Update(item);
            return(await _repoWorker.SaveAll());
        }
Exemple #14
0
 public async Task <IActionResult> UpdateOperation(OperationDto update)
 {
     if (await _workerService.UpdateOperation(update))
     {
         return(NoContent());
     }
     return(BadRequest($"Updating Worker {update.WorkerID} failed on save"));
 }
        public ActionResult Save(OperationDto model)
        {
            var saveState = BusinessHelper.BuildSaveState(Request);

            _operationBll.HttpPostSave(model, saveState);

            return(RedirectToAction("Index", "Operation"));
        }
Exemple #16
0
        public async Task <IActionResult> AddAsync([FromBody] OperationDto operation)
        {
            var appUser = await userManager.FindByNameAsync(User.Identity.Name);

            Guid operationId = this.operationService.AddOperation(operation, appUser);

            return(Ok(operationId));
        }
Exemple #17
0
 static void PrintOperation(OperationDto operation)
 {
     Console.WriteLine($"{nameof(operation.Id)}: {operation.Id}" +
                       $"\t{nameof(operation.CreationDate)}: {operation.CreationDate}" +
                       $"\t{nameof(operation.OperationType)}: {operation.OperationType}" +
                       $"\t{nameof(operation.Values)}: {string.Join(',', operation.Values)}" +
                       $"\t{nameof(operation.Result)}: {operation.Result}");
 }
Exemple #18
0
 private static int CalculateInternal(OperationDto parameter)
 {
     if (parameter is null)
     {
         throw new ArgumentNullException(nameof(parameter));
     }
     return(parameter.First - parameter.Second);
 }
Exemple #19
0
        private void CheckIfOperationTypeIsCorrect(OperationDto operation, Dal.Interface.IContext context)
        {
            var baOpTyRepo = Factory.GetBankAccountOperationTypeRepository(context);

            if (!baOpTyRepo.GetAllByBankAccountId(operation.BankAccountId.Value).Any(ot => ot.Id.Equals(operation.BankAccountOperationTypeId)))
            {
                throw new DaGetServiceException(String.Format("Type d'opération {0} non autorisé sur ce compte {1}", operation.BankAccountOperationTypeId, operation.BankAccountId));
            }
        }
Exemple #20
0
 public bool Update(OperationDto operation)
 {
     if (presenter.Update(operation))
     {
         OperationBindingList.ResetBindings();
         return(true);
     }
     return(false);
 }
Exemple #21
0
 public bool Remove(OperationDto operation)
 {
     if (presenter.Remove(operation))
     {
         OperationBindingList.Remove(operation);
         return(true);
     }
     return(false);
 }
Exemple #22
0
        public IActionResult Put([FromBody] OperationDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(Ok(_operationService.Update(User.Identity.GetUserId(), model)));
        }
Exemple #23
0
 public bool Insert(OperationDto operation)
 {
     if (presenter.Insert(operation) != null)
     {
         OperationBindingList.Add(operation);
         return(true);
     }
     return(false);
 }
Exemple #24
0
 public async Task PublishOperationCompletedAsync(OperationDto operation)
 => await _hubContextWrapper.PublishToUserAsync(operation.UserId,
                                                "operation_completed",
                                                new
 {
     id   = operation.Id,
     name = operation.Name
 }
                                                );
Exemple #25
0
 public async Task PublishOperationPendingAsync(OperationDto operation)
 => await _hubContextWrapper.PublishToUserAsync(operation.UserId,
                                                "operation_pending",
                                                new
 {
     id   = operation.Id,
     name = operation.Name
 }
                                                );
        public ResponseDto RemoveOperatin(SecurityResourceDto resource, OperationDto operation)
        {
            var result = SecurityResourceServiceAdapter.Execute(s => s.RemoveOperation(resource, operation));

            if (result.Response.HasException)
            {
                return(null);
            }
            return(result);
        }
Exemple #27
0
 private void SetupMocks(Operation createOperation, OperationDto createOperationDto, User user)
 {
     MockUnitOfWork.Setup(x => x.UserRepository.GetAsync(It.IsAny <int>()))
     .ReturnsAsync(user);
     MockUnitOfWork.Setup(x => x.OperationRepository.Create(It.IsAny <Operation>()));
     MockUnitOfWork.Setup(x => x.WalletRepository.Update(It.IsAny <Wallet>()));
     MockUnitOfWork.Setup(x => x.CommitAsync());
     MockMapper.Setup(x => x.Map <Operation>(It.IsAny <OperationDto>())).Returns(createOperation);
     MockMapper.Setup(x => x.Map <OperationDto>(It.IsAny <Operation>())).Returns(createOperationDto);
 }
Exemple #28
0
 private void VerifyMocks(Wallet userWallet, int userId, Operation createOperation,
                          OperationDto createOperationDto, Times methodCalls)
 {
     MockUnitOfWork.Verify(x => x.UserRepository.GetAsync(userId));
     MockUnitOfWork.Verify(x => x.OperationRepository.Create(createOperation), methodCalls);
     MockUnitOfWork.Verify(x => x.WalletRepository.Update(userWallet), methodCalls);
     MockUnitOfWork.Verify(x => x.CommitAsync(), methodCalls);
     MockMapper.Verify(x => x.Map <Operation>(createOperationDto), methodCalls);
     MockMapper.Verify(x => x.Map <OperationDto>(createOperation), methodCalls);
 }
Exemple #29
0
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="entity"></param>
 public void Add(OperationDto entity)
 {
     using (_unitOfWork)
     {
         var info       = AutoMapperHelper.Signle <OperationDto, Operation>(entity);
         var repository = _unitOfWork.Repository <Operation>();
         repository.Add(info);
         _unitOfWork.Commit();
     }
 }
Exemple #30
0
        public bool Remove(OperationDto Operation)
        {
            ResponseDto response = OperationServiceAdapter.Execute(s => s.Delete(Operation));

            if (response.Response.HasException)
            {
                return(false);
            }
            return(true);
        }
 public OperationViewModel(OperationDto operation)
 {
     Operation = operation;
 }
 public OperationViewModel()
 {
     Operation = new OperationDto();
 }