Ejemplo n.º 1
0
        public void Update(UserModel model)
        {
            long userId;

            switch (model.RoleType)
            {
            case RoleType.Admin:
                userId = _admins.Update(model.Id, model.Name, model.Authentication.Login, model.Email);
                break;

            case RoleType.Manager:
                userId = _managers.Update(model.Id, model.Name, model.Authentication.Login, model.Email);
                break;

            case RoleType.Broker:
                userId = _brokers.Update(model.Id, model.Name, model.Authentication.Login, model.Email);
                break;

            default:
                throw new ArgumentOutOfRangeException("model", @"Unknown role " + model.RoleType);
            }

            if (!string.IsNullOrEmpty(model.Authentication.NewPassword))
            {
                _users.SetPassword(userId, model.Authentication.NewPassword);
            }
        }
Ejemplo n.º 2
0
 public void Update_ShouldThrowNotImplementedException()
 {
     try
     {
         _brokerRepositoryMock.Update(_brokerListMock.ElementAt(0));
     }
     catch (Exception ex)
     {
         Assert.AreEqual(ex.GetType(), typeof(NotImplementedException));
     }
 }
Ejemplo n.º 3
0
        public Task <bool> Handle(UpdateBrokerCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            var broker = new Broker(message.Id, message.Name);


            _brokerRepository.Update(broker);

            if (Commit())
            {
                _bus.RaiseEvent(new BrokerUpdatedEvent(broker.Id, broker.Name));
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 4
0
        public async Task <Result> CompleteProject(string authToken, string projectId)
        {
            var project = await _client.GetProjectAsync(projectId);

            if (project == null)
            {
                throw new InvalidResult("Couldn't fetch project for projectId: " + projectId);
            }

            var result = await _brokerRepository.GetByProjectId(project.Id);

            if (result == null)
            {
                throw new InvalidResult("Result doesn't exist");
            }

            if (result.State != ResultStates.PaymentSubmittet)
            {
                throw new InvalidResult("Couldn't be set to done, as the result hasn't processed payments yet");
            }

            var toReplace = result;

            toReplace.State = ResultStates.Done;

            try
            {
                await _brokerRepository.Update(result.Id, toReplace);
            }
            catch (System.Exception)
            {
                throw;
            }

            try
            {
                bool response = await _client.PostEvent(authToken, new EventData
                {
                    Type      = "result",
                    OwnerId   = result.EmployerId,
                    ProjectId = result.ProjectId,
                    Content   = JsonConvert.SerializeObject(new
                    {
                        ResultId  = result.Id,
                        ProjectId = result.ProjectId,
                        Status    = ResultStates.Done,
                        Files     = result.FileUrl
                    })
                });

                if (!response)
                {
                    throw new InvalidResult("Service failed");
                }
            }
            catch (Exception e)
            {
                await _brokerRepository.Update(result.Id, result);

                throw new InvalidResult("Couldn't bind to service Collaboration: " + e.Message);
            }

            return(toReplace);
        }