/// <summary>
        /// Create a device
        /// </summary>
        /// <param name="deviceTwinObj">DeviceTwinModel</param>
        /// <returns>DeviceModel</returns>
        public async Task <DeviceModel> CreateDevice(DeviceTwinModel deviceTwinObj)
        {
            //If device doesn't exist, throw exception
            DeviceDAO deviceEntity = _mapper.Map <DeviceDAO>(deviceTwinObj);

            deviceEntity.Id = await _repoDevices.CreateItemAsync(deviceEntity);

            if (_repoDevices.IsDocumentKeyNull(deviceEntity))
            {
                throw new Exception($"An error occured when creating a new device: {deviceTwinObj.DeviceId}");
            }

            return(_mapper.Map <DeviceModel>(deviceEntity));
        }
        /// <summary>
        /// Create a new response
        /// </summary>
        /// <param name="responseObj">ResponseCreationModel</param>
        /// <returns>ResponseModel</returns>
        public async Task <ResponseModel> CreateResponse(ResponseCreationModel responseObj)
        {
            //Instantiate the actions
            InstantiateResponseActions(responseObj.ActionPlan.OpenActions);
            InstantiateResponseActions(responseObj.ActionPlan.CloseActions);

            ResponseDAO response = new ResponseDAO()
            {
                ActionPlan            = _mapper.Map <ResponseActionPlanDAOObject>(responseObj.ActionPlan),
                ResponderUserId       = responseObj.ResponderUserId,
                ResponseState         = RESPONSE_STATE_ACTIVE,
                PrimaryEventClusterId = responseObj.PrimaryEventClusterId,
                Geolocation           = _mapper.Map <GeolocationDAOObject>(responseObj.Geolocation)
            };



            response.Id = await _repoResponses.CreateItemAsync(response);

            if (_repoResponses.IsDocumentKeyNull(response))
            {
                throw new Exception($"An error occured when creating a new response");
            }

            ResponseModel output = _mapper.Map <ResponseModel>(response);

            return(output);
        }
Exemple #3
0
        /// <summary>
        /// Create a notification
        /// </summary>
        /// <param name="notification">NotificationCreationModel</param>
        /// <returns>NotificationModel</returns>
        public async Task <NotificationModel> CreateNotification(NotificationCreationModel notification)
        {
            var date = DateTime.UtcNow;

            NotificationDAO notificationDao = new NotificationDAO()
            {
                NotificationText = notification.NotificationText,
                CreationDate     = date,
                UpdateDate       = date,
                ResponseId       = notification.ResponseId.ToString(),
                Status           = notification.Status,
                Tags             = notification.Tags,
                Title            = notification.Title,
                User             = notification.User
            };

            notificationDao.Id = await _repoNotifications.CreateItemAsync(notificationDao);

            if (_repoNotifications.IsDocumentKeyNull(notificationDao))
            {
                throw new Exception($"An error occured when creating a new notification");
            }

            NotificationModel output = _mapper.Map <NotificationModel>(notificationDao);

            return(output);
        }
Exemple #4
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));
        }
Exemple #5
0
        public async Task InitializeDB()
        {
            ConsoleHelper.WriteInfo($"Create Saga Collection");
            await _repoSagas.EnsureDatabaseAndCollectionExists();

            ConsoleHelper.WriteInfo($"Create Bot Collection");
            await _repoBot.EnsureDatabaseAndCollectionExists();

            ConsoleHelper.WriteInfo($"Create ChatReports Collection");
            await _repoChatReports.EnsureDatabaseAndCollectionExists();

            ConsoleHelper.WriteInfo($"Create Devices Collection");
            await _repoDevices.EnsureDatabaseAndCollectionExists();

            ConsoleHelper.WriteInfo($"Create Responses Collection");
            await _repoResponses.EnsureDatabaseAndCollectionExists();

            ConsoleHelper.WriteInfo($"Create EventClusters Collection");
            await _repoEventClusters.EnsureDatabaseAndCollectionExists();

            ConsoleHelper.WriteInfo($"Create Notifications Collection");
            await _repoNotifications.EnsureDatabaseAndCollectionExists();

            ConsoleHelper.WriteInfo($"Create ActionPlans Collection");
            await _repoActionPlans.EnsureDatabaseAndCollectionExists();

            foreach (var actionPlanDAO in ActionPlanDB.GetActionPlans())
            {
                await _repoActionPlans.CreateItemAsync(actionPlanDAO);
            }

            await Task.Delay(5000);
        }
Exemple #6
0
        public async Task <Doctor> CreateAsync(Doctor newdoctor)
        {
            newdoctor.CreatedDate = DateTime.UtcNow;
            newdoctor.EntityId    = Guid.NewGuid();
            var item = await Respository.CreateItemAsync(newdoctor, newdoctor.Speciality.Id);

            return((Doctor)(dynamic)item);
        }
Exemple #7
0
        public async Task <Patient> CreateAsync(Patient newpatient)
        {
            newpatient.CreatedDate      = DateTime.UtcNow;
            newpatient.EntityId         = Guid.NewGuid();
            newpatient.Address.EntityId = Guid.NewGuid();
            var item = await Respository.CreateItemAsync(newpatient, newpatient.Address.ZipCode);

            return((Patient)(dynamic)item);
        }
Exemple #8
0
        private async Task CreateTemplateDocument(ICosmosDBRepository <Template> templateRepository, Template template)
        {
            Template templateObj = await templateRepository.GetItemAsync(template.Id);

            if (templateObj == null)
            {
                await templateRepository.CreateItemAsync(template);
            }
        }
Exemple #9
0
        private async Task CreateCategoryDocument(ICosmosDBRepository <Category> categoryRepository, Category category)
        {
            Category categoryObj = await categoryRepository.GetItemAsync(category.Id);

            if (categoryObj == null)
            {
                await categoryRepository.CreateItemAsync(category);
            }
        }
Exemple #10
0
        public async Task <Appointment> CreateAsync(Appointment newappointment)
        {
            newappointment.CreatedDate = DateTime.UtcNow;
            newappointment.HasConflict = false;
            newappointment.EntityId    = Guid.NewGuid();
            var item = await Respository.CreateItemAsync(newappointment, newappointment.DoctorId);

            return((Appointment)item);
        }
Exemple #11
0
        public async Task <string> CreateNoteTemplate(NoteTemplateModel noteTemplate)
        {
            string result = await _repoNoteTemplates.CreateItemAsync(noteTemplate);

            if (_config.UseCache)
            {
                await GetNotesFromEvent(noteTemplate.EventId, true);
            }
            return(result);
        }
Exemple #12
0
        public async Task <ActionResult> CreateAsync([Bind("Id,Name,Description,Completed")] Item item)
        {
            if (ModelState.IsValid)
            {
                await _cosmosDBRepository.CreateItemAsync(item);

                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
Exemple #13
0
        public async Task <DeliveryModel> CreateDeliveryForEvent(string eventId, DeliveryModel delivery)
        {
            await _repoDeliveries.CreateItemAsync(delivery);

            if (_config.UseCache)
            {
                await GetDeliveriesForEvent(eventId, true);
            }

            return(await GetDeliveryForEvent(eventId, delivery.DeliveryId));
        }
Exemple #14
0
        public static async Task Run(
            EventGridEvent eventGridEvent, ICosmosDBRepository <Item> cosmosDBRepository,
            ILogger log)
        {
            log.LogInformation("TodoFunction function started processing a request.");

            log.LogInformation(eventGridEvent.Data.ToString());

            var item = JsonConvert.DeserializeObject <Item>(eventGridEvent.Data.ToString());

            cosmosDBRepository.Initialize();
            await cosmosDBRepository.CreateItemAsync(item);
        }
        /// <summary>
        /// Create an action plan
        /// </summary>
        /// <param name="actionPlanObj">ActionPlanCreationModel</param>
        /// <returns>ActionPlanModel</returns>
        public async Task <ActionPlanModel> CreationActionPlan(ActionPlanCreationModel actionPlanObj)
        {
            ActionPlanDAO plan = _mapper.Map <ActionPlanDAO>(actionPlanObj);

            plan.Id = await _repoActionPlans.CreateItemAsync(plan);

            if (_repoActionPlans.IsDocumentKeyNull(plan))
            {
                throw new Exception($"An error occured when creating a new action plan");
            }

            return(_mapper.Map <ActionPlanModel>(plan));
        }
        private async Task SaveUpdatedRoute(RouteModel route)
        {
            RouteModel prev = await _repoRoutes.GetItemAsync(p => p.RouteId == route.RouteId);

            if (prev == null)
            {
                await _repoRoutes.CreateItemAsync(route);
            }
            else
            {
                route.Id = prev.Id;
                await _repoRoutes.UpdateItemAsync(prev.Id, route);
            }
        }
Exemple #17
0
        private async Task <string> CreateNewRegistration(string eventId, string locationId, string email, string firstName, string lastName, string zipCode)
        {
            string newId = await _repoRegistrations.CreateItemAsync(new RegistrationModel()
            {
                Email     = email,
                FirstName = firstName,
                LastName  = lastName,
                ZipCode   = zipCode,
                Events    = new List <RegistrationEventModel>()
                {
                    CreateNewRegistrationEvent(eventId, locationId)
                }
            });

            return(newId);
        }
        public async Task <ChatReportModel> CreateChatReport(ChatReportLogCreationModel reportLogObj)
        {
            ReportLogDAOObject reportLogDAO = Mapper.Map <ReportLogDAOObject>(reportLogObj.Message);
            ChatReportDAO      newReportDAO = new ChatReportDAO()
            {
                ChannelId  = reportLogObj.ChannelId,
                ReportLogs = new List <ReportLogDAOObject>()
                {
                    reportLogDAO
                },
                User = Mapper.Map <ChatUserDAOObject>(reportLogObj.User)
            };

            newReportDAO.Id = await _repoChatReports.CreateItemAsync(newReportDAO);

            if (string.IsNullOrEmpty(newReportDAO.Id))
            {
                throw new Exception($"An error occured when creating a new chat report: {reportLogObj.User.Id}");
            }

            return(Mapper.Map <ChatReportModel>(newReportDAO));
        }
        public async Task <bool> AddConversationReference(ConversationReference conversationReference)
        {
            ChatUserSessionDAO newDAO = Mapper.Map <ChatUserSessionDAO>(conversationReference);

            ChatUserSessionDAO oldDAO = await _repoChatUserSessions.GetItemAsync(newDAO.Id);

            if (oldDAO == null)
            {
                string id = await _repoChatUserSessions.CreateItemAsync(newDAO);

                return(!string.IsNullOrEmpty(id));
            }
            else
            {
                oldDAO.BotId          = newDAO.BotId;
                oldDAO.BotName        = newDAO.BotName;
                oldDAO.ChannelId      = newDAO.ChannelId;
                oldDAO.ConversationId = newDAO.ConversationId;
                oldDAO.ServiceUrl     = newDAO.ServiceUrl;
                oldDAO.Name           = newDAO.Name;
                oldDAO.Role           = newDAO.Role;

                try
                {
                    return(await _repoChatUserSessions.UpdateItemAsync(oldDAO));
                }
                catch (DocumentClientException e)
                {
                    //Update concurrency issue, retrying
                    if (e.StatusCode == HttpStatusCode.PreconditionFailed)
                    {
                        return(await AddConversationReference(conversationReference));
                    }
                    throw e;
                }
            }
        }
        public async Task <string> CreateEvent(EventModel eventObj)
        {
            eventObj.EventLocations = new List <EventLocationModel>()
            {
                new EventLocationModel()
                {
                    Id = "Location1", Goal = 1000, LocationName = "Room 1"
                }
            };
            eventObj.EventSentiments = new List <EventSentimentModel>()
            {
                new EventSentimentModel()
                {
                    Name = "Sentiment1"
                },
                new EventSentimentModel()
                {
                    Name = "Sentiment2"
                },
                new EventSentimentModel()
                {
                    Name = "Sentiment3"
                }
            };
            eventObj.EventViews             = new List <EventViewModel>();
            eventObj.PayPalApi              = new EventPayPalApiModel();
            eventObj.PayPalApi.MerchantInfo = new PayPalMerchantInfo();

            string result = await _repoEvents.CreateItemAsync(eventObj);

            if (_config.UseCache)
            {
                await GetEvent(result, true);
            }
            return(result);
        }
Exemple #21
0
        public async Task <IActionResult> CreateUserTemplate([FromBody] Template template)
        {
            Domain.Model.User currentUser = await EnsureCurrentUser();

            string userId = currentUser.Id.ToLower();

            //Ensure user values and unique ID are set server side.
            template.BaseTemplateId = template.Id;
            template.Id             = Guid.NewGuid().ToString();
            template.DocType        = TemplateDocumentType.User;
            template.UserId         = userId;
            template.CreationDate   = DateTime.Now;
            template.ModifiedDate   = DateTime.Now;

            //Create new user template
            string newId = await _templateRepo.CreateItemAsync(template);

            if (string.IsNullOrEmpty(newId))
            {
                logger.LogError("API CreateUserTemplate error: There was an error while creating the template {TemplateName}", template.Name);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            return(Ok(newId));
        }
        public async Task <IActionResult> CreateCustomGroup([FromBody] CustomGroupModel customGroup)
        {
            logger.LogInformation("Create custom group called");

            //New Guid
            customGroup.Id    = Guid.NewGuid().ToString();
            customGroup.Count = 0;

            //Get number of custom groups
            IEnumerable <CustomGroupModel> customGroupsEnum = await _GroupsRepo.GetItemsAsync();

            if (customGroupsEnum != null)
            {
                List <CustomGroupModel>        customGroups = new List <CustomGroupModel>();
                IEnumerator <CustomGroupModel> enumator     = customGroupsEnum.GetEnumerator();
                while (enumator.MoveNext())
                {
                    customGroups.Add(enumator.Current);
                }

                customGroup.Order = customGroups.Count;
            }
            {
                customGroup.Order = 0;
            }

            //Create new user template
            string newId = await _GroupsRepo.CreateItemAsync(customGroup);

            if (string.IsNullOrEmpty(newId))
            {
                logger.LogError("Create custom group - Exception: {0}", customGroup.Name);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            return(Ok(newId));
        }
Exemple #23
0
 public void Post([FromBody] models.product value)
 {
     _cosmosDBRepository.CreateItemAsync(value).Wait();
 }