Exemplo n.º 1
0
        public IActionResult CreateNewActvity([FromBody] CreateActivityRequest requestModel)
        {
            try
            {
                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                CreateNewActivity newActivityModel = new CreateNewActivity()
                {
                    ActivityName = requestModel.ActivityName,
                    ActivityType = requestModel.ActivityType,
                    Message      = requestModel.Message,
                    ResourceType = requestModel.ResourceType
                };
                var activityId = MongoConnector.CreateNewActivity(newActivityModel);

                return(Ok($"ActivityId:{activityId}"));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
        internal static string CreateNewActivity(CreateNewActivity activity)
        {
            try
            {
                if (_kitsuneServer == null)
                {
                    InitializeConnection();
                }
                var activityCollection = _kitsuneDatabase.GetCollection <KitsuneActivity>(KitsuneActivityCollection);

                string          activityId     = ObjectId.GenerateNewId().ToString();
                KitsuneActivity activityObject = new KitsuneActivity()
                {
                    ActivityName = activity.ActivityName,
                    ActivityType = activity.ActivityType,
                    Message      = activity.Message,
                    ResourceType = activity.ResourceType,
                    CreatedOn    = new DateTime(),
                };
                activityObject._id = activityId;
                activityCollection.InsertOne(activityObject);

                return(activityId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }