Пример #1
0
        public IActionResult Post([FromBody] Service service)
        {
            if (!string.IsNullOrEmpty(service.Id))
            {
                return(new StatusCodeResult(StatusCodes.Status400BadRequest));
            }
            if (string.IsNullOrEmpty(service.Name))
            {
                return(new StatusCodeResult(StatusCodes.Status400BadRequest));
            }
            if (!Enum.IsDefined(typeof(ServiceTypeEnum), service.Type))
            {
                return(new StatusCodeResult(StatusCodes.Status400BadRequest));
            }

            var serviceElastic = ServiceElastic.Create(service.Name, service.Type, service.Alias, service.Description);

            RemoveServiceAlias(serviceElastic.Alias);
            serviceQuery.Index(serviceElastic);

            GlobalStore.ServiceAliases.Set(serviceElastic.Alias, serviceElastic.Id);

            var serviceModel = serviceElastic.ToServiceModel <Service>();

            serviceModel.ActualProcessId = serviceElastic.ProcessIdList.FirstOrDefault(pid => GlobalStore.Processes.IsExist(pid));

            return(base.CreatedAtRoute("GetService", new { Controller = "Services", id = serviceElastic.Id }, serviceModel));
        }