Esempio n. 1
0
        public async Task <ActionResult <BrokerViewModel> > Post([FromBody] BrokerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _brokerRepository.Create(_mapper.Map <Broker>(model));

            return(model);
        }
Esempio n. 2
0
        public async Task <Result> InitializeResult(string authToken, Result result, string userId)
        {
            result.FreelancerId = userId;
            result.State        = ResultStates.FilesUploaded;

            var exists = await _brokerRepository.GetByProjectId(result.ProjectId);

            if (exists != null)
            {
                throw new InvalidResult("Result already exists, cannot initialize");
            }

            var createdResult = await _brokerRepository.Create(result);

            if (createdResult != null)
            {
                try
                {
                    bool response = await _client.PostEvent(authToken, new EventData
                    {
                        Type      = "result",
                        OwnerId   = userId,
                        ProjectId = result.ProjectId,
                        Content   = JsonConvert.SerializeObject(new
                        {
                            ResultId  = createdResult.Id,
                            ProjectId = createdResult.ProjectId,
                            Status    = ResultStates.FilesUploaded
                        })
                    });

                    if (!response)
                    {
                        throw new InvalidResult("Service failed");
                    }
                }
                catch (Exception e)
                {
                    await _brokerRepository.Remove(createdResult);

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

            return(createdResult ??
                   throw new InvalidResult());
        }