public IActionResult RenameResource(string projectid, [FromQuery] string user, [FromQuery] string oldname, [FromQuery] string newname)
        {
            try
            {
                if (string.IsNullOrEmpty(user))
                {
                    return(Unauthorized());
                }
                var requestModel = new RenameResourceModel
                {
                    NewSourceName = newname,
                    OldSourceName = oldname,
                    ProjectId     = projectid,
                    UserEmail     = user
                };
                if (string.IsNullOrEmpty(oldname) || string.IsNullOrEmpty(newname))
                {
                    return(BadRequest("Resource name can not be empty"));
                }
                if (MongoConnector.RenameResource(requestModel))
                {
                    return(Ok(true));
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #2
0
        public IActionResult KitsuneUpdateDomain([FromQuery] string websiteid, [FromQuery] string newDomain, [FromQuery] string clientid)
        {
            try
            {
                if (string.IsNullOrEmpty(clientid) || BasePluginConfigGenerator.GetBasePlugin(clientid).GetClientId() != clientid.Trim().ToUpper())
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }

                var requestModel = new KitsuneUpdateDomainRequestModel {
                    CustomerId = websiteid, NewDomain = newDomain
                };
                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(Ok(MongoConnector.UpdateDomainName(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Пример #3
0
        public static Task <MongoWineRepository> Create(string dbHost, int dbPort, string dbName, string userName, string password)
        {
            Deferred <MongoWineRepository> deferred = Deferred.Create <MongoWineRepository>();

            Dictionary <string, object> serverOptions = new Dictionary <string, object>("auto_reconnect", true);
            Dictionary <string, object> dbOptions     = new Dictionary <string, object>("w", "0");

            MongoServer    dbServer    = new MongoServer(dbHost, dbPort, serverOptions);
            MongoConnector dbConnector = new MongoConnector(dbName, dbServer, dbOptions);

            dbConnector.Open(delegate(Exception openError, MongoDatabase db) {
                db.Authenticate(userName, password, delegate(Exception authError, bool success) {
                    if (success)
                    {
                        db.CreateCollection("wines", delegate(Exception collectionError, MongoCollection collection) {
                            if (collection != null)
                            {
                                MongoWineRepository repository = new MongoWineRepository(db, collection);
                                deferred.Resolve(repository);
                            }
                            else
                            {
                                deferred.Reject();
                            }
                        });
                    }
                    else
                    {
                        deferred.Reject();
                    }
                });
            });

            return(deferred.Task);
        }
Пример #4
0
        public async Task <ResponseStatus> BlockUser(DbUserModel requestingDbUserModel)
        {
            if (requestingDbUserModel.HasClaim(UserClaim.Admin) || HasClaim(UserClaim.Admin))
            {
                return(ResponseFactory.createResponse(ResponseType.PERMISSION_DENIED));
            }

            // Check if a relationship already exists for the two players.
            var relationExists = MongoConnector.GetFriendCollection()
                                 .Find(it => (it.PlayerId == UserModel.Id && it.FriendId == requestingDbUserModel.UserModel.Id))
                                 .CountDocuments() != 0;

            // Remove all pre-existing relations
            await MongoConnector.GetFriendCollection().DeleteManyAsync(it =>
                                                                       (it.FriendId == requestingDbUserModel.UserModel.Id && it.PlayerId == UserModel.Id) ||
                                                                       (it.PlayerId == requestingDbUserModel.UserModel.Id && it.FriendId == UserModel.Id));

            await MongoConnector.GetFriendCollection().InsertOneAsync(new FriendModel
            {
                Id              = Guid.NewGuid().ToString(),
                FriendId        = requestingDbUserModel.UserModel.Id,
                FriendStatus    = FriendStatus.StatusBlocked,
                PlayerId        = UserModel.Id,
                UnixTimeCreated = DateTime.UtcNow.ToFileTimeUtc(),
            });

            return(ResponseFactory.createResponse(ResponseType.SUCCESS));
        }
Пример #5
0
        public async Task <IActionResult> Issue(string quoteId, [FromBody] object content)
        {
            try
            {
                var policyNumber = GeneratePolicyNumber();
                var request      = JObject.Parse(content.ToString());
                request["policyNumber"] = policyNumber;

                Console.WriteLine("request content here - " + content);

                var mongo = new MongoConnector(MongoConnectionString, MONGO_DB_NAME);

                mongo.InsertData(MONGO_PolicyIssue_Collection, request);

                var policyObject = mongo.GetPolicyObject(quoteId);

                policyObject.Add(new JProperty("policyNumber", policyNumber));
                policyObject.Add(new JProperty("issue-info", request));

                var message = await KafkaService.SendMessage(policyObject.ToString(), _logger);

                //var message = "success";
                PolicyData.Add(policyObject.ToString());
                var finalResult = new JObject(new JProperty("policyNumber", policyNumber), new JProperty("result", new JObject(new JProperty("status", message), new JProperty("policy", policyObject))));
                return(Ok(finalResult.ToString()));
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(Ok());
            }
        }
        public IActionResult UpdateCacheInvalidationStatus([FromRoute] string websiteid, [FromQuery] string clientid, [FromQuery] int nextInvalidationInSec)
        {
            try
            {
                if (string.IsNullOrEmpty(clientid) || BasePluginConfigGenerator.GetBasePlugin(clientid).GetClientId() != clientid.Trim().ToUpper())
                {
                    return(Unauthorized());
                }

                if (string.IsNullOrEmpty(websiteid))
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(new ValidationResult("Invalid websiteid"))));
                }
                if (nextInvalidationInSec == 0)
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(new ValidationResult("Provide valid next invalidation in secnd paramater"))));
                }

                return(new CommonActionResult(MongoConnector.UpdateCacheInvalidationStatus(websiteid, nextInvalidationInSec)));
            }
            catch (Exception ex)
            {
                return(new CommonActionResult(CommonAPIResponse.InternalServerError(ex)));
            }
        }
Пример #7
0
        public void Setup()
        {
            client = ClientHelper.GetClient();

            // Clear the database every test.
            MongoConnector.FlushCollections();
        }
Пример #8
0
 public IActionResult GetWebsiteDataByPropertyPath([FromRoute] string schemaid, [FromBody] GetWebsiteDataByPropertyPathV2 requestModel, [FromRoute] string clientid = null)
 {
     try
     {
         var userId = AuthHelper.AuthorizeRequest(Request);
         if (string.IsNullOrEmpty(userId) && (string.IsNullOrEmpty(clientid) || BasePluginConfigGenerator.GetBasePlugin(clientid).GetClientId() != clientid.Trim().ToUpper()))
         {
             return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
         }
         requestModel.SchemaId = schemaid;
         var validationResult = requestModel.Validate();
         if (validationResult.Any())
         {
             return(BadRequest(validationResult));
         }
         var result        = new List <GetWebsiteDataByPropertyResponseModel>();
         var segmentRequet = new GetWebsiteDataByPropertyPath()
         {
             SchemaId = requestModel.SchemaId, UserEmail = requestModel.UserEmail, WebsiteId = requestModel.WebsiteId
         };
         foreach (var segments in requestModel.BulkPropertySegments)
         {
             segmentRequet.PropertySegments = segments;
             result.Add(MongoConnector.GetWebsiteDataByPropertyPath(segmentRequet));
         }
         return(new CommonActionResult(CommonAPIResponse.OK(result)));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
Пример #9
0
        public IActionResult UpdateWebsiteData([FromRoute] string schemaname, [FromBody] UpdateWebsiteDataRequestModel requestModel)
        {
            ///TODO : Chheck that mongodb driver support long for skip and limit
            // string userid = Request.Headers.Authorization.ToString();
            // command.UserId = userid;
            try
            {
                var userId = AuthHelper.AuthorizeRequest(Request);
                if (string.IsNullOrEmpty(userId))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }
                else
                {
                    requestModel.UserId = userId;
                }

                requestModel.SchemaName = schemaname;
                // requestModel.SchemaName = schemaname.ToUpper();
                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(new CommonActionResult(MongoConnector.UpdateWebsiteData(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Пример #10
0
        public IActionResult GetWebsiteDataByType([FromRoute] string schemaname, [FromQuery] string website, [FromQuery] string className)
        {
            try
            {
                var requestModel = new GetWebsiteDataByTypeRequestModel
                {
                    SchemaName = schemaname,
                    WebsiteId  = website,
                    ClassName  = className,
                };

                var userId = AuthHelper.AuthorizeRequest(Request);
                if (string.IsNullOrEmpty(userId))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }
                else
                {
                    requestModel.UserId = userId;
                }

                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }
                return(Ok(MongoConnector.GetWebsiteDataByType(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Пример #11
0
        public IActionResult CreateLanguage([FromBody] dynamic requestModel)
        {
            try
            {
                var userId = requestModel["UserId"] != null ? requestModel["UserId"].Value.ToString() : null;
                if (Request.Headers.ContainsKey("Authorization"))
                {
                    userId = Request.Headers.ContainsKey("Authorization") ? Request.Headers["Authorization"].ToString() : userId;
                }
                var jsonObject  = ((Newtonsoft.Json.Linq.JProperty)((Newtonsoft.Json.Linq.JContainer)requestModel).Last).Value;
                var entity      = JsonParserHelper.ParseToKEntity(jsonObject);
                var tempCommand = new CreateOrUpdateLanguageEntityRequestModel()
                {
                    UserId = userId,
                    Entity = entity
                };
                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(Ok(MongoConnector.CreateOrUpdateLanguageEntity(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Пример #12
0
        public IActionResult AddOrUpdateWebsite([FromRoute] string schemaname, [FromBody] AddOrUpdateWebsiteRequestModel requestModel, [FromRoute] string clientid = null, [FromRoute] string schemaid = null)
        {
            try
            {
                var userId = AuthHelper.AuthorizeRequest(Request);

                if (string.IsNullOrEmpty(userId) && (string.IsNullOrEmpty(clientid) || BasePluginConfigGenerator.GetBasePlugin(clientid).GetClientId() != clientid.Trim().ToUpper()))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }

                requestModel.UserId     = userId;
                requestModel.SchemaId   = schemaid;
                requestModel.SchemaName = schemaname;

                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(Ok(MongoConnector.AddDataForWebsite(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Пример #13
0
        public IActionResult GetLanguageEntityForTypeBySegment([FromRoute] string languageid, [FromQuery] string className, [FromQuery] string websiteId)
        {
            try
            {
                string UserId = AuthHelper.AuthorizeRequest(Request);

                var requestModel = new GetSimilarPropertiesInLanguageEntityRequestModel
                {
                    EntityId  = languageid,
                    ClassName = className,
                    WebsiteId = websiteId
                };
                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(Ok(MongoConnector.GetSimilarPropertyPathSegments(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Пример #14
0
 public IActionResult GetLanguageEntity([FromRoute] string languageid, [FromRoute] string clientid, bool propertygroup = false)
 {
     try
     {
         if (!string.IsNullOrEmpty(clientid) && BasePluginConfigGenerator.GetBasePlugin(clientid).GetClientId() == clientid.Trim().ToUpper())
         {
             var requestModel = new GetLanguageEntityRequestModel
             {
                 EntityId = languageid,
             };
             var validationResult = requestModel.Validate();
             if (validationResult.Any())
             {
                 return(BadRequest(validationResult));
             }
             if (propertygroup)
             {
                 return(Ok(MongoConnector.GetLanguageEntityByPropertyGroup(requestModel)));
             }
             else
             {
                 return(Ok(MongoConnector.GetLanguageEntity(requestModel)));
             }
         }
         return(Unauthorized());
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public IActionResult DeactivateWebsites([FromBody] DeActivateWebsitesRequestModel deactivateRequestModel)
        {
            try
            {
                var userId = AuthHelper.AuthorizeRequest(Request);
                if (string.IsNullOrEmpty(userId))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }
                DeActivateWebsitesRequestModel requestModel = new DeActivateWebsitesRequestModel
                {
                    WebsiteIds = deactivateRequestModel.WebsiteIds,
                    UserId     = userId
                };
                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(validationResult)));
                }

                return(new CommonActionResult(MongoConnector.DeactivateWebsites(requestModel)));
            }
            catch (Exception ex)
            {
                return(new CommonActionResult(CommonAPIResponse.InternalServerError(ex)));
            }
        }
Пример #16
0
        public IActionResult UpdateWebsiteDataById([FromRoute] string schemaid, [FromRoute] string clientid, [FromBody] UpdateWebsiteDataRequestModel requestModel)
        {
            ///TODO : Chheck that mongodb driver support long for skip and limit
            // string userid = Request.Headers.Authorization.ToString();
            // command.UserId = userid;
            try
            {
                if (string.IsNullOrEmpty(clientid) || BasePluginConfigGenerator.GetBasePlugin(clientid).GetClientId() != clientid.Trim().ToUpper())
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }

                requestModel.SchemaId = schemaid;
                // requestModel.SchemaName = schemaname.ToUpper();
                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(new CommonActionResult(MongoConnector.UpdateWebsiteData(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
        public IActionResult GenerateKAdminLoginToken([FromQuery] string websiteId, [FromQuery] string source = "IDE")
        {
            try
            {
                var userId = AuthHelper.AuthorizeRequest(Request);
                if (string.IsNullOrEmpty(userId))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }
                GenerateKAdminLoginTokenRequestModel requestModel = new GenerateKAdminLoginTokenRequestModel
                {
                    WebsiteId  = websiteId,
                    UserId     = userId,
                    ExpiryTime = source == "IDE" ? 2 : 30,
                    Source     = source
                };

                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(validationResult)));
                }

                return(new CommonActionResult(MongoConnector.GenerateKAdminLoginToken(requestModel)));
            }
            catch (Exception ex)
            {
                return(new CommonActionResult(CommonAPIResponse.InternalServerError(ex)));
            }
        }
Пример #18
0
        public IActionResult DeleteWebsiteData([FromRoute] string schemaname, [FromBody] DeleteDataObjectRequestModel requestModel)
        {
            try
            {
                var userId = AuthHelper.AuthorizeRequest(Request);
                if (string.IsNullOrEmpty(userId))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }
                else
                {
                    requestModel.UserId = userId;
                }

                requestModel.SchemaName = schemaname;
                // requestModel.SchemaName = schemaname.ToUpper();
                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(Ok(MongoConnector.DeleteObject(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
        public IActionResult ChangeKitsuneWebsiteUserPassword(string WebsiteId, string WebsiteUserId, [FromBody] UpdateWebsiteUserPasswordRequestModel requestModel)
        {
            try
            {
                requestModel.WebsiteId     = WebsiteId;
                requestModel.WebsiteUserId = WebsiteUserId;
                var developerId = AuthHelper.AuthorizeRequest(Request);
                if (string.IsNullOrEmpty(developerId))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }
                requestModel.DeveloperId = developerId;
                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(validationResult)));
                }

                return(new CommonActionResult(MongoConnector.ChangeWebsiteUserPassword(requestModel)));
            }
            catch (Exception ex)
            {
                return(new CommonActionResult(CommonAPIResponse.InternalServerError(ex)));
            }
        }
Пример #20
0
        public IActionResult MapWebsiteToWebAction([FromBody] MapSchemaToProjectRequestModel requestModel)
        {
            try
            {
                var userId = AuthHelper.AuthorizeRequest(Request);
                if (string.IsNullOrEmpty(userId))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }
                else
                {
                    requestModel.UserId = userId;
                }

                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(Ok(MongoConnector.MapSchemaToProject(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Пример #21
0
        public async Task <bool> SaveToDatabase()
        {
            // Save to user collection
            await MongoConnector.GetUserCollection().InsertOneAsync(new UserModelMapper(UserModel));

            return(true);
        }
Пример #22
0
        public IActionResult GetIntellisense([FromRoute] string projectid)
        {
            try
            {
                var requestModel = new GetIntellisenseRequestModel
                {
                    ProjectId = projectid
                };

                var userId = AuthHelper.AuthorizeRequest(Request);
                if (string.IsNullOrEmpty(userId))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }
                else
                {
                    requestModel.UserId = userId;
                }

                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(Ok(MongoConnector.GetIntellisense(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Пример #23
0
        public async Task <SubmitGameEventResponse> AddPlayerGameEvent(DbUserModel player, GameEventRequest request)
        {
            GameEventModel eventModel = toGameEventModel(player, request);

            // Ensure the event happens after current time.
            GameTick currentTick = new GameTick(DateTime.FromFileTimeUtc(GameConfiguration.UnixTimeStarted), DateTime.UtcNow);

            if (eventModel.OccursAtTick <= currentTick.GetTick())
            {
                return(new SubmitGameEventResponse()
                {
                    Status = ResponseFactory.createResponse(ResponseType.INVALID_REQUEST),
                });;
            }

            // TODO: validate event.

            await MongoConnector.GetGameEventCollection().InsertOneAsync(new GameEventModelMapper(eventModel));

            return(new SubmitGameEventResponse()
            {
                Status = ResponseFactory.createResponse(ResponseType.SUCCESS),
                EventId = eventModel.Id,
            });
        }
Пример #24
0
        public IActionResult UpdateLanguage([FromBody] dynamic requestModel, [FromRoute] string id)
        {
            try
            {
                var userId      = requestModel["UserId"].Value.ToString();
                var jsonObject  = ((Newtonsoft.Json.Linq.JProperty)((Newtonsoft.Json.Linq.JContainer)requestModel).Last).Value;
                var entity      = JsonParserHelper.ParseToKEntity(jsonObject);
                var tempCommand = new CreateOrUpdateLanguageEntityRequestModel()
                {
                    Entity     = entity,
                    UserId     = userId,
                    LanguageId = id
                };
                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(Ok(MongoConnector.CreateOrUpdateLanguageEntity(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Пример #25
0
        public string GetPolicyData([FromQuery] string quoteId)
        {
            var mongo        = new MongoConnector(MongoConnectionString, MONGO_DB_NAME);
            var policyObject = mongo.GetPolicyObject(quoteId);

            return(policyObject.ToString());
        }
Пример #26
0
        public IActionResult VersionLanguageSchema(VersionLanguageSchema requestModel)
        {
            try
            {
                var userId = AuthHelper.AuthorizeRequest(Request);
                if (string.IsNullOrEmpty(userId))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }
                else
                {
                    requestModel.UserId = userId;
                }

                var validationResult = requestModel.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(Ok(MongoConnector.VersionLanguageSchema(requestModel)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
        public bool InvalidateDataCache(string customerId)
        {
            var objectid = new ObjectId();

            if (ObjectId.TryParse(customerId, out objectid))
            {
                var customer = ((WebsiteDetailsResponseModel)MongoConnector.GetKitsuneWebsiteDetails(customerId).Response);
                if (customer != null)
                {
                    var cloudProviderDetails = MongoConnector.GetCloudProviderDetails(customer.ProjectId);
                    if (cloudProviderDetails != null && cloudProviderDetails.provider == Kitsune.Models.Cloud.CloudProvider.AliCloud)
                    {
                        return(InvalidateAliCloudCDNCache(customerId, customer.WebsiteUrl, customer.KitsuneProjectVersion.ToString()));
                    }
                    else
                    {
                        if (customer.IsSSLEnabled)
                        {
                            InvalidateDataCachePerDomain($"https://{customer.WebsiteUrl}");
                        }
                        else
                        {
                            InvalidateDataCachePerDomain($"http://{customer.WebsiteUrl}");
                        }

                        InvalidateDataCachePerDomain($"{customer.WebsiteUrl}");
                    }
                }
            }
            return(false);
        }
        public IActionResult CheckWebsiteTagAvailability(string websitetag, [FromQuery] string clientId, [FromQuery] string projectId)
        {
            var developerId = AuthHelper.AuthorizeRequest(Request);

            if (string.IsNullOrEmpty(developerId))
            {
                return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
            }

            try
            {
                try
                {
                    if (String.IsNullOrEmpty(clientId) && !String.IsNullOrEmpty(projectId))
                    {
                        clientId = MongoConnector.GetClientIdFromProjectId(projectId);
                    }
                }
                catch { }

                return(new CommonActionResult(MongoConnector.CheckWebsiteTagAvailability(websitetag, clientId)));
            }
            catch (Exception ex)
            {
                return(new CommonActionResult(CommonAPIResponse.InternalServerError(ex)));
            }
        }
Пример #29
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));
            }
        }
Пример #30
0
        public IActionResult StartCrawling([FromBody] StartKrawlRequestModel request)
        {
            try
            {
                var validationResult = request.Validate();
                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                try
                {
                    request.Url = Helpers.GenerateUrl(request.Url);
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
                return(Ok(MongoConnector.StartKrawling(request)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }