Esempio n. 1
0
        public async Task <IActionResult> RegisterNewAttendee([FromBody] RegistrationCreatedMessage message)
        {
            //Formatting
            string email     = message.Email.ToLower();
            string firstName = FormatName(message.FirstName);
            string lastName  = FormatName(message.LastName);
            string zipCode   = message.ZipCode.ToUpper();

            //Test for pre-existence (let the email be the unique key for the registrant)
            RegistrationModel registration = await _repoRegistrations.GetItemAsync(p => p.Email == email);

            if (registration == null)
            {
                //Create
                string newId = await CreateNewRegistration(message.EventId, message.LocationId, email, firstName, lastName, zipCode);

                return(!string.IsNullOrEmpty(newId) ? Ok() : StatusCode((int)HttpStatusCode.InternalServerError));
            }
            else
            {
                //Update
                bool result = await UpdateRegistrationUserInfo(message.EventId, message.LocationId, firstName, lastName, zipCode, registration);

                return(result ? Ok() : StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> GetTemplateById(string templateId)
        {
            Template template = await _templateRepo.GetItemAsync(templateId);

            //Not found
            if (template == null)
            {
                logger.LogError("API GetTemplateById error: Template with id {TemplateId} not found.", templateId);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            //If not a template, return error
            if (template.DocType != TemplateDocumentType.User && template.DocType != TemplateDocumentType.CommonTemplate)
            {
                logger.LogError("API GetTemplateById error: {TemplateId} is not a template.", templateId);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            //If user template, check user
            if (template.DocType == TemplateDocumentType.User)
            {
                Domain.Model.User currentUser = await EnsureCurrentUser();

                string userId = currentUser.Id.ToLower();

                //If user doesn't match, return error
                if (template.UserId.ToLower() != userId)
                {
                    logger.LogError("API GetTemplateById error: Template with id {TemplateId} was found but the user {UserId} does not match.", templateId, userId);
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }
            }

            return(Ok(template));
        }
Esempio n. 3
0
        public async Task DeleteAsync(string id)
        {
            Doctor item = await Respository.GetItemAsync(id);

            // just using the manager to do something extra

            if (item == null)
            {
                throw new Exception("Id can not be found");
            }
            await Respository.DeleteItemAsync(id, item.Speciality.Id);
        }
Esempio n. 4
0
        public async Task DeleteAsync(string id)
        {
            Patient item = await Respository.GetItemAsync(id);

            // just using the manager to do something extra

            if (item == null)
            {
                throw new Exception("Id can not be found");
            }
            await Respository.DeleteItemAsync(id, item.Address.ZipCode);
        }
Esempio n. 5
0
        /// <summary>
        /// Create an Event Cluster
        /// </summary>
        /// <param name="eventObj">EventClusterCreationModel</param>
        /// <returns>EventClusterModel</returns>
        public async Task <EventClusterModel> CreateEventCluster(EventClusterCreationModel eventObj)
        {
            //If device doesn't exist, throw exception
            DeviceDAO deviceEntity = await _repoDevices.GetItemAsync(eventObj.DeviceId);

            if (deviceEntity == null)
            {
                throw new Exception($"No device found that matches DeviceId: {eventObj.DeviceId}");
            }

            EventClusterDAO eventCluster = new EventClusterDAO()
            {
                Id         = eventObj.EventClusterId.ToString(),
                Device     = _mapper.Map <EventClusterDeviceDAOObject>(deviceEntity),
                EventType  = eventObj.EventType.ToLower(),
                EventCount = 1,
                Events     = new EventDAOObject[] { _mapper.Map <EventDAOObject>(eventObj) },
                StartDate  = eventObj.Date
            };

            eventCluster.Id = await _repoEventClusters.CreateItemAsync(eventCluster);

            if (_repoEventClusters.IsDocumentKeyNull(eventCluster))
            {
                throw new Exception($"An error occured when creating a new cluster id for DeviceId: {eventObj.DeviceId}");
            }

            return(_mapper.Map <EventClusterModel>(eventCluster));
        }
        public async Task <IActionResult> GetCustomGroupById(string customGroupId)
        {
            try
            {
                logger.LogInformation("Get custom group called");

                var device = await _GroupsRepo.GetItemAsync(customGroupId);

                return(Ok(device));
            }
            catch (Exception e)
            {
                logger.LogError(e, "Get custom group - Exception: {message}", e.Message);
                throw;
            }
        }
Esempio n. 7
0
        public async Task <ActionResult> EditAsync(string id)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            Item item = await _cosmosDBRepository.GetItemAsync(id);

            if (item == null)
            {
                return(NotFound());
            }

            return(View(item));
        }
Esempio n. 8
0
        private async Task CreateCategoryDocument(ICosmosDBRepository <Category> categoryRepository, Category category)
        {
            Category categoryObj = await categoryRepository.GetItemAsync(category.Id);

            if (categoryObj == null)
            {
                await categoryRepository.CreateItemAsync(category);
            }
        }
Esempio n. 9
0
        private async Task CreateTemplateDocument(ICosmosDBRepository <Template> templateRepository, Template template)
        {
            Template templateObj = await templateRepository.GetItemAsync(template.Id);

            if (templateObj == null)
            {
                await templateRepository.CreateItemAsync(template);
            }
        }
Esempio n. 10
0
        public async Task <RouteModel> GetRoute(string routeId, bool forceRefresh = false)
        {
            RouteModel route = null;

            if (!_dictRoutes.ContainsKey(routeId) || !_config.UseCache || (_config.UseCache && forceRefresh))
            {
                route = await _repoRoutes.GetItemAsync(p => p.RouteId == routeId);

                if (route == null)
                {
                    _logger.LogDebug($"GetRoute: No routes found for {routeId}.");
                }
                _dictRoutes[routeId] = route;
            }
            else
            {
                route = _dictRoutes[routeId];
            }
            return(route);
        }
Esempio n. 11
0
 /// <summary>
 /// Retrieve a User Template from a TemplateId
 /// </summary>
 /// <param name="templateId">Template ID</param>
 /// <returns></returns>
 private async Task <Template> GetUserTemplate(string templateId)
 {
     try
     {
         //User currentUser = _UserService.GetCurrentUser();
         return(await _TemplateRepo.GetItemAsync(templateId));
     }
     catch (Exception e)
     {
         Log.Error(e, string.Format("Error while retrieving the template {0}.", templateId));
         return(null);
     }
 }
Esempio n. 12
0
        public async Task <EventModel> GetEvent(string eventId, bool useCache = false)
        {
            EventModel eventModel = null;

            if (!useCache || !_config.UseCache || !_dictEvents.ContainsKey(eventId))
            {
                eventModel = await _repoEvents.GetItemAsync(eventId);

                _dictEvents[eventId] = eventModel;
            }
            else
            {
                eventModel = _dictEvents[eventId];
            }
            return(eventModel);
        }
Esempio n. 13
0
        public async Task Run()
        {
            try
            {
                //Load event to test
                EventModel vEvent = await _repoEvents.GetItemAsync(_config.EventId);

                //Load note templates
                IEnumerable <NoteTemplateModel> noteTemplatesEnum = await _repoNoteTemplates.GetItemsAsync();

                _nodeTemplates = new List <NoteTemplateModel>();
                foreach (var noteTemplate in noteTemplatesEnum)
                {
                    _nodeTemplates.Add(noteTemplate);
                }

                //Set up timers for buttons / notes
                foreach (EventLocationModel eventLocation in vEvent.EventLocations)
                {
                    Timer newTimer = new Timer();
                    newTimer.Elapsed += (sender, e) => SendButtonMessage(sender, e, newTimer, vEvent.Id, eventLocation.Id);
                    newTimer.Interval = _rand.Next(_config.TimerMin, _config.TimerMax);
                    newTimer.Start();
                    _timers.Add(newTimer);

                    Timer newTimerNotes = new Timer();
                    newTimerNotes.Elapsed += (sender, e) => SendNoteMessage(sender, e, newTimerNotes, vEvent.Id, eventLocation.Id);
                    newTimerNotes.Interval = _rand.Next(_config.TimerMin, _config.TimerMax);
                    newTimerNotes.Start();
                    _timers.Add(newTimerNotes);
                }

                Console.WriteLine("Press a key to exit.");
                Console.Read();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Retrieve a User Template from a TemplateId
        /// </summary>
        /// <param name="parameter">Template ID</param>
        /// <returns></returns>
        private async Task <Template> GetUserTemplate(object parameter)
        {
            if (parameter == null)
            {
                return(null);
            }

            string templateId = parameter.ToString();

            try
            {
                //User currentUser = _UserService.GetCurrentUser();
                Template template = await _TemplateRepo.GetItemAsync(templateId);

                Template = template;
                return(template);
            }
            catch (Exception e)
            {
                Log.Error(e, string.Format("Error while retrieving the template {0}.", templateId));
                return(null);
            }
        }
        public async Task <ChatReportModel> GetChatReportById(string reportId)
        {
            ChatReportDAO reportEntity = await _repoChatReports.GetItemAsync(reportId);

            return(Mapper.Map <ChatReportModel>(reportEntity));
        }
        /// <summary>
        /// Get a device from a device id
        /// </summary>
        /// <param name="deviceId">Device Id</param>
        /// <returns>DeviceModel</returns>
        public async Task <DeviceModel> GetDevice(Guid deviceId)
        {
            DeviceDAO deviceEntity = await _repoDevices.GetItemAsync(deviceId);

            return(_mapper.Map <DeviceModel>(deviceEntity));
        }
Esempio n. 17
0
        /// <summary>
        /// Get Event Cluster by Id
        /// </summary>
        /// <param name="eventClusterId">Event Cluster Id</param>
        /// <returns>EventClusterModel</returns>
        public async Task <EventClusterModel> GetEventCluster(Guid eventClusterId)
        {
            EventClusterDAO eventCluster = await _repoEventClusters.GetItemAsync(eventClusterId);

            return(_mapper.Map <EventClusterModel>(eventCluster));
        }
Esempio n. 18
0
        public async Task <models.product> Get(string id)
        {
            var item = await _cosmosDBRepository.GetItemAsync(id);

            return(item);
        }
        /// <summary>
        /// Get action plan from an action plan Id
        /// </summary>
        /// <param name="actionPlanId">Action Plan Id</param>
        /// <returns>ActionPlanModel</returns>
        public async Task <ActionPlanModel> GetActionPlan(Guid actionPlanId)
        {
            ActionPlanDAO plan = await _repoActionPlans.GetItemAsync(actionPlanId);

            return(_mapper.Map <ActionPlanModel>(plan));
        }
        public async Task <IEnumerable <ChatUserReadStatusModel> > GetUsersReadStatusPerUser(string userId)
        {
            var result = await _repoChatUserSessions.GetItemAsync(userId);

            return(Mapper.Map <IEnumerable <ChatUserReadStatusModel> >(result?.UsersReadStatus));
        }
        /// <summary>
        /// Get a response full object by Id
        /// </summary>
        /// <param name="responseId">Response Id</param>
        /// <returns>ResponseModel</returns>
        public async Task <ResponseModel> GetResponse(Guid responseId)
        {
            ResponseDAO response = await _repoResponses.GetItemAsync(responseId);

            return(_mapper.Map <ResponseModel>(response));
        }