public async Task <bool> AddUserToConversationAsync(ConversationViewModel request)
 {
     foreach (var participantId in request.ParticipantIds)
     {
         var participant = new Participant()
         {
             Id             = Guid.NewGuid(),
             ConversationId = request.Id,
             UserId         = participantId
         };
         _participantRepository.Add(participant);
     }
     return(await _unitOfWork.SaveChangeAsync() > 0);
 }
 // POST api/Participant
 // [Authorize]
 public IHttpActionResult PostParticipant(Participant item /*, HttpPostedFileBase file*/)
 {
     //Dictionary<string, object> dict = new Dictionary<string, object>();
     //  string str = files(file);
     //  item.Img = str;
     try
     {
         var httpRequest = HttpContext.Current.Request;
         item = repository.Add(item);
         repository.Save();
         var    response = Request.CreateResponse <Participant>(HttpStatusCode.Created, item);
         string uri      = Url.Link("DefaultApi", new { id = item.PId });
         response.Headers.Location = new Uri(uri);
         // return Ok();
         var data = repository.GetAll();
         if (data == null)
         {
             return(NotFound());
         }
         return(Ok(data));
     }
     catch
     {
         return(InternalServerError());
     }
 }
Exemplo n.º 3
0
 private static void TryAddParticipant(Participant participant)
 {
     try
     {
         _participantRepository.Add(participant);
     }
     catch (RepositoryError)
     {
     }
 }
Exemplo n.º 4
0
        public IActionResult AddParticipant(ContestViewModel model)
        {
            var participant = new Participant();

            participant.ContestId = model.Id;
            participant.Name      = model.Participant.Name;
            _participantRepository.Add(participant);
            _participantRepository.Commit();

            return(RedirectToAction("Contest", "Home", new { id = model.Id }));
        }
Exemplo n.º 5
0
        public IActionResult OnPost(string name, string attend)
        {
            if (!string.IsNullOrEmpty(name) && attend == "on")
            {
                Repository.Add(new Participant(name));

                return(new RedirectToPageResult("/Participants"));
            }

            return(new RedirectToPageResult("/Vote"));
        }
        public IActionResult Create([FromBody] Participant participant)
        {
            try
            {
                if (participant == null || !ModelState.IsValid)
                {
                    return(BadRequest("Invalid State"));
                }

                ParticipantRepository.Add(participant);
            }
            catch (Exception)
            {
                return(BadRequest("Error while creating"));
            }
            return(Ok(participant));
        }
Exemplo n.º 7
0
        public IActionResult Store(ParticipantRegisterViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Participant participant = _participantRepository.FindUniqueByEmail(model.Email);

                    if (participant != null)
                    {
                        ModelState.AddModelError("Email", "E-mail já cadastrado");

                        return(View("Index", model));
                    }

                    participant = new Participant
                    {
                        Name      = model.Name,
                        Email     = model.Email,
                        Birthdate = model.Birthdate,
                        Gender    = model.Gender,
                        Password  = HashExtension.Create(model.Password, Environment.GetEnvironmentVariable("AUTH_SALT")),
                        CreatedAt = DateTime.Now
                    };

                    _participantRepository.Add(participant);
                    _participantRepository.SaveChanges();

                    TempData["Success"] = "Registro efetuado com sucesso!";

                    return(RedirectToAction("Index", "Login"));
                }
            }
            catch (Exception exception)
            {
                TempData["Error"] = "Internal server error";
                _logger.LogError("Login error: " + exception);
            }

            return(View("Index", model));
        }
        /// <summary>
        /// Добавить вызов в очередь и сообщить об этом оператору.
        /// </summary>
        public async Task AddIncomingCall(IncomingInboxIntegrationEvent incomingInboxIntegrationEvent)
        {
            var itemId = incomingInboxIntegrationEvent.ItemId;

            if (itemId == default)
            {
                _logger.Warning($"Empty {nameof(itemId)}: {itemId}");
                return;
            }

            var extension = incomingInboxIntegrationEvent.CallerExtension;

            if (string.IsNullOrWhiteSpace(extension))
            {
                _logger.Warning($"AddIncomingCall. Empty CallerExtension. {nameof(itemId)}: {itemId}");
                return;
            }

            using UnitOfWork unitOfWork = _unitOfWork.Begin();

            bool isSms = incomingInboxIntegrationEvent.ContractInboxItemType == ContractInboxItemType.Sms;

            var smsMessageData = _mapper.Map <SmsMessageData>(incomingInboxIntegrationEvent.Sms);
            var caller         = await GetCaller(extension);

            if (isSms)
            {
                var locationMetadata = JsonConvert.SerializeObject(smsMessageData.Location ?? new SmsLocationData {
                    Position = new SmsPositionData()
                });
                var sms = new Sms(itemId)
                {
                    Status           = SmsStatus.New,
                    ArrivalDateTime  = incomingInboxIntegrationEvent.ArrivalDateTime,
                    Text             = smsMessageData.Message,
                    Applicant        = caller,
                    LocationMetadata = locationMetadata,
                    Timestamp        = smsMessageData.Timestamp
                };

                await _smsRepository.Add(sms);

                await unitOfWork.CommitAsync();

                _logger.Debug($"Added incoming sms with id: {itemId}");
            }
            else
            {
                var result = await _callManagementServiceClient.AddIncomingCall(
                    itemId,
                    caller.Id,
                    incomingInboxIntegrationEvent.ArrivalDateTime);

                if (result.IsFailure)
                {
                    _logger.Error($"AddIncomingCall. {result.ErrorMessage}");
                    return;
                }

                await _participantRepository.Add(caller);

                await unitOfWork.CommitAsync();
            }

            await _phoneHubMessageService.NotifyUsersAboutInboxUpdate(incomingInboxIntegrationEvent.InboxId);
        }
Exemplo n.º 9
0
 public bool CreateParticipant(ParticipantDto participant)
 {
     return(_participantRepository.Add(participant));
 }
Exemplo n.º 10
0
        public void Handle(CreateParticipantCommand command)
        {
            var participant = new Participant(command.Id, command.Name);

            _repository.Add(participant);
        }