public IActionResult RemoveClient(string clientID)
 {
     IActionResult result;
     Guid clientIDGuid;
     if (StringUtils.GuidTryDecode(clientID, out clientIDGuid))
     {
         Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
         if (client != null)
         {
             BusinessLogicFactory.Clients.DeleteClient(client);
             result = new NoContentResult();
         }
         else
         {
             result = new NotFoundResult();
         }
     }
     else
     {
         result = new NotFoundResult();
     }
     return result;
 }
示例#2
0
        public ActionResult GetAvatar()
        {
            ActionResult response = null;

            try
            {
                int    userId       = int.Parse(Request.Query["userId"]);
                string avatarString = userRepository.Get(userId).Avatar;
                byte[] avatar       = Convert.FromBase64String(avatarString ?? "");
                response = File(avatar, "image/jpeg");
            }
            catch
            {
                response = new NoContentResult();
            }
            return(response);
        }
示例#3
0
        public void Populate(CheckoutOutput response)
        {
            Output = response;

            if (response == null)
            {
                ViewModel = new NoContentResult();
                return;
            }

            ViewModel = new ObjectResult(new Model(
                                             response.Basket.BasketId,
                                             response.Customer.CustomerId,
                                             response.OrderDate,
                                             response.TotalPrice
                                             ));
        }
示例#4
0
        public void Populate(DepositOutput response)
        {
            Output = response;

            if (response == null)
            {
                ViewModel = new NoContentResult();
                return;
            }

            ViewModel = new ObjectResult(new Model(
                                             response.Transaction.Amount,
                                             response.Transaction.Description,
                                             response.Transaction.TransactionDate,
                                             response.UpdatedBalance
                                             ));
        }
示例#5
0
        public void Populate(WithdrawOutput output)
        {
            Output = output;

            if (output == null)
            {
                ViewModel = new NoContentResult();
                return;
            }

            ViewModel = new ObjectResult(new
            {
                Amount          = output.Transaction.Amount,
                Description     = output.Transaction.Description,
                TransactionDate = output.Transaction.TransactionDate,
                UpdateBalance   = output.UpdatedBalance,
            });
        }
示例#6
0
        public void Populate(RegisterOutput response)
        {
            Output = response;

            if (response == null)
            {
                ViewModel = new NoContentResult();
                return;
            }

            Model model = new Model(
                response.Customer.CustomerId,
                response.Customer.Personnummer,
                response.Customer.Name
                );

            ViewModel = new CreatedAtRouteResult("GetCustomer", new { customerId = model.CustomerId }, model);
        }
示例#7
0
        public async Task Test4Put()
        {
            MetaHumanMutateModel mutateModel = new MetaHumanMutateModel
            {
                Name        = "TestMetaUpdated",
                Description = "This is a meta created by the unit test",
                AlterEgo    = "Unit test",
                Status      = 0
            };

            MetaHumansController controller = new MetaHumansController(_context, null);
            IActionResult        result     = await controller.Put(this.id, mutateModel);

            NoContentResult ok = result as NoContentResult;

            Assert.NotNull(ok);
            Assert.Equal(204, ok.StatusCode);
        }
        public async Task DeletePersonalSiteTest()
        {
            DbContextOptionsBuilder <SharePointContext> optionsBuilder = new DbContextOptionsBuilder <SharePointContext>();
            SharePointContext context = new SharePointContext(optionsBuilder.Options);
            var builder = new ConfigurationBuilder();

            builder.AddUserSecrets <Startup>();
            IConfiguration       config     = builder.Build();
            SharePointController controller = new SharePointController(config, context);
            // public async Task<List<SharePointItem>> PersonalSites(string url)
            IActionResult result = await controller.DeleteSite(personalSiteURL_);

            Assert.IsNotNull(result);
            NoContentResult ok = result as NoContentResult;

            Assert.IsNotNull(ok);
            Assert.AreEqual(StatusCodes.Status204NoContent, ok.StatusCode);
        }
        public async Task PutDescriptionTest()
        {
            // Arrange
            var                productsController = this.CreateProductsController();
            const long         id          = 10;
            ProductDescription description = new ProductDescription {
                Description = "null and some text"
            };
            var expected = new NoContentResult();

            this.mockDataContext.Setup(m => m.PutDescription(id, description.Description)).Returns(Task.FromResult((IActionResult)expected));
            // Act
            var result = await productsController.PutDescription(id, description).ConfigureAwait(false);

            // Assert
            Assert.Equal(expected, result);
            this.mockRepository.VerifyAll();
        }
示例#10
0
        public async Task <IActionResult> Update(int id, [FromBody] TodoViewModel todo)
        {
            IActionResult response = BadRequest("Failed to update data in database");

            if (ModelState.IsValid)
            {
                var newTodo = Mapper.Map <Todo>(todo);

                _repository.UpdateTodo(id, newTodo);

                if (await _repository.SaveChangesAsync())
                {
                    response = new NoContentResult();
                }
            }

            return(response);
        }
示例#11
0
        public void Populate(WithdrawOutput response)
        {
            Output = response;

            if (response == null)
            {
                ViewModel = new NoContentResult();
                return;
            }

            ViewModel = new ObjectResult(new
            {
                Amount          = response.Transaction.Amount,
                Description     = response.Transaction.Description,
                TransactionDate = response.Transaction.TransactionDate,
                UpdateBalance   = response.UpdatedBalance,
            });
        }
示例#12
0
        public void GivenChangeFeedController_WhenExecutedActionThrowsException_ThenAuditLogShouldBeLogged()
        {
            var result = new NoContentResult();

            var actionExecutedContext = new ActionExecutedContext(
                new ActionContext(_httpContext, new RouteData(), new ControllerActionDescriptor()
            {
                DisplayName = "Executed ChangeFeed."
            }),
                new List <IFilterMetadata>(),
                FilterTestsHelper.CreateMockChangeFeedController());

            actionExecutedContext.Exception = new Exception("Test Exception.");

            _filter.OnActionExecuted(actionExecutedContext);

            _auditHelper.Received(1).LogExecuted(_httpContext, _claimsExtractor);
        }
示例#13
0
        public async Task CreateScore_When_Payload_Is_Valid_Then_Return_NoContent()
        {
            _mockScoresRepository
            .Setup(x => x.GetScoreByPlayer(It.IsAny <string>()))
            .ReturnsAsync(new ScoreModel());

            _mockScoresService
            .Setup(x => x.UpdateScore(It.Is <string>(o => o == "Dave"), It.IsAny <ScoresRequest>()))
            .Returns(Task.CompletedTask);

            var controller = new ScoresController(_mockLogger, _mockScoresService.Object, _mockScoresRepository.Object);

            var expectedResponse = new NoContentResult();
            var actual           = await controller.UpdatePlayerScore("Dave", new ScoresRequest { Score = 123 });

            actual.Should().BeEquivalentTo(expectedResponse);

            _mockScoresService.Verify();
        }
        public async Task GetListReturnsnoContentWhenDataNotPresent()
        {
            // Arrange
            var expectedResult = new NoContentResult();
            IEnumerable <AppRegistrationModel>?fakeAppRegistrationModels = null;
            var function = new GetListHttpTrigger(fakeLogger, fakeDocumentService);

            A.CallTo(() => fakeDocumentService.GetAllAsync(A <string> .Ignored)).Returns(fakeAppRegistrationModels);

            // Act
            var result = await function.Run(A.Fake <HttpRequest>()).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeDocumentService.GetAllAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();

            var statusResult = Assert.IsType <NoContentResult>(result);

            Assert.Equal(expectedResult.StatusCode, statusResult.StatusCode);
        }
示例#15
0
        public static ActionResult <T> ToActionResult <T>(this Result <T> result)
        {
            var actionResult = default(ActionResult);

            if (result.IsFailed)
            {
                actionResult = new UnprocessableEntityObjectResult(result.Errors);
            }
            else if (result.IsSucceeded)
            {
                actionResult = new OkObjectResult(result.Container);
            }
            else
            {
                actionResult = new NoContentResult();
            }

            return(new ActionResult <T>(actionResult));
        }
示例#16
0
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "servers/{name}")] HttpRequest req, TraceWriter log, ExecutionContext context, string name)
        {
            IActionResult result = null;

            try
            {
                var config = KubernetesClientConfiguration.BuildConfigFromConfigFile($@"{context.FunctionAppDirectory}\config\config.txt");

                new Minecraft(config).Delete(req.Query["name"]);

                result = new NoContentResult();
            }
            catch (Exception e)
            {
                result = new OkObjectResult(new { name, error = e.Message });
            }

            return(result as ActionResult);
        }
示例#17
0
        public IActionResult RemoveObjectInstance(string clientID, string definitionID, string instanceID)
        {
            IActionResult result;

            Guid definitionIDGuid, clientIDGuid;

            if (StringUtils.GuidTryDecode(definitionID, out definitionIDGuid) && StringUtils.GuidTryDecode(clientID, out clientIDGuid))
            {
                int organisationID = User.GetOrganisationID();
                Model.ObjectDefinition definition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, definitionIDGuid);
                if (definition != null)
                {
                    Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
                    if (client != null)
                    {
                        Model.Object instance = BusinessLogicFactory.Clients.GetObject(client, definition.ObjectDefinitionID, instanceID);
                        if (instance != null)
                        {
                            BusinessLogicFactory.Clients.SaveObject(client, instance, Model.TObjectState.Delete);
                            result = new NoContentResult();
                        }
                        else
                        {
                            result = new NotFoundResult();
                        }
                    }
                    else
                    {
                        result = new NotFoundResult();
                    }
                }
                else
                {
                    result = new NotFoundResult();
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return(result);
        }
        public void EditarProdutoEntidadeIdValido()
        {
            string id = ObjectId.GenerateNewId().ToString();

            var controller = new ProdutoController(mockMapper.Object, produtoServiceMock.Object);

            IActionResult result = controller.Put(id, new ProdutoViewModel()
            {
                Id         = id,
                Nome       = "Geladeira B W600",
                Categorias = new string[] { "Geladeira" },
                Descricao  = "",
                Preco      = 2500
            });

            NoContentResult okResult = result as NoContentResult;

            Assert.NotNull(okResult);
            Assert.Equal(204, okResult.StatusCode);
        }
示例#19
0
        public void Populate(CustomerOutput output)
        {
            Output = output;

            if (output == null)
            {
                ViewModel = new NoContentResult();
                return;
            }

            List <AccountDetailsModel> accounts = new List <AccountDetailsModel>();

            foreach (var account in output.Accounts)
            {
                List <TransactionModel> transactions = new List <TransactionModel>();

                foreach (var item in account.Transactions)
                {
                    var transaction = new TransactionModel(
                        item.Amount,
                        item.Description,
                        item.TransactionDate);

                    transactions.Add(transaction);
                }

                accounts.Add(new AccountDetailsModel(
                                 account.AccountId,
                                 account.CurrentBalance,
                                 transactions));
            }

            CustomerDetailsModel model = new CustomerDetailsModel(
                output.CustomerId,
                output.Personnummer,
                output.Name,
                accounts
                );

            ViewModel = new ObjectResult(model);
        }
示例#20
0
        public async void DeleteOwner()
        {
            using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions))
            {
                IMapper mapper = CreateMapperConfig();

                MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context));

                for (int i = 0; i < 10; ++i)
                {
                    OwnerDto owner = new OwnerDto()
                    {
                        DateBirth = DateTime.Now,
                        FirstName = $"Test{i}",
                        LastName  = $"{i}Test"
                    };

                    myProfileController.PostOwner(owner);
                }
            }

            using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions))
            {
                IMapper mapper = CreateMapperConfig();

                MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context));

                IActionResult result = await myProfileController.DeleteOwner(3);

                NoContentResult noContentResult = result as NoContentResult;

                IActionResult getResult = await myProfileController.GetOwners();

                OkObjectResult  okResult = getResult as OkObjectResult;
                List <OwnerDto> owners   = okResult.Value as List <OwnerDto>;

                Assert.NotNull(noContentResult);
                Assert.Equal(204, noContentResult.StatusCode);
                Assert.Equal(9, owners.Count);
            }
        }
示例#21
0
        public void Populate(BasketOutput output)
        {
            Output = output;

            if (output == null)
            {
                ViewModel = new NoContentResult();
                return;
            }

            DateTime orderDateTime = DateTime.Now;

            OrderDetailsModel order = new OrderDetailsModel(output.BasketId, output.TotalPrice, orderDateTime);

            List <BookDetailsModel> books = Utils.GetBookDetailsModel(output.Books);

            ViewModel = new ObjectResult(new BasketDetailsModel(
                                             output.BasketId,
                                             output.TotalPrice,
                                             books));
        }
        public void Delete_Should_delete_ticket_by_id_return_statusCode_204()
        {
            // Arrange

            var ticketservice = A.Fake <ITicketsService>();

            A.CallTo(() => ticketservice.GetById(A <int> ._)).Returns(ticket1In);

            var ticketsController = new TicketsController(ticketservice);

            //Act
            var actionResult = ticketsController.Delete(1);

            //Assert
            Assert.NotNull(actionResult);

            NoContentResult result = actionResult as NoContentResult;

            Assert.NotNull(result);
            Assert.AreEqual(204, result.StatusCode);
        }
示例#23
0
        public async Task <IActionResult> GetFlow([FromBody] FlowFilterFromBody filterData)
        {
            var result = await _mobileService.GetFlow(filterData);

            if (result.IsSuccess)
            {
                if (result.Value == null)
                {
                    var responseNoContent = new NoContentResult();
                    return(responseNoContent);
                }
                var data     = result.Value;
                var response = Envelope.Ok(data);
                return(Ok(response));
            }
            else
            {
                var responseBadRequest = new BadRequestResult();
                return(responseBadRequest);
            }
        }
示例#24
0
        public void Populate(CustomerOutput output)
        {
            Output = output;

            if (output == null)
            {
                ViewModel = new NoContentResult();
                return;
            }

            List <OrderDetailsModel> orders = Utils.GetOrderDetailsModel(output.Orders);

            CustomerDetailsModel model = new CustomerDetailsModel(
                output.CustomerId,
                output.Personnummer,
                output.Name,
                orders
                );

            ViewModel = new ObjectResult(model);
        }
示例#25
0
        public void Populate(RegisterOutput response)
        {
            Output = response;

            if (response == null)
            {
                ViewModel = new NoContentResult();
                return;
            }

            List <TransactionModel> transactions = new List <TransactionModel>();

            foreach (var item in response.Account.Transactions)
            {
                var transaction = new TransactionModel(
                    item.Amount,
                    item.Description,
                    item.TransactionDate);

                transactions.Add(transaction);
            }

            AccountDetailsModel account = new AccountDetailsModel(
                response.Account.AccountId,
                response.Account.CurrentBalance,
                transactions);

            List <AccountDetailsModel> accounts = new List <AccountDetailsModel>();

            accounts.Add(account);

            Model model = new Model(
                response.Customer.CustomerId,
                response.Customer.Personnummer,
                response.Customer.Name,
                accounts
                );

            ViewModel = new CreatedAtRouteResult("GetCustomer", new { customerId = model.CustomerId }, model);
        }
示例#26
0
        public async void TestPutRequest()
        {
            // Arrange
            Note testNote = await mockDbHelper.GetTestResultData();

            Mock <INotesService> mockRepo = new Mock <INotesService>();

            mockRepo.Setup(repo => repo.PutNotes(testNote)).Returns(mockDbHelper.GetTestResultData());
            NotesController controller = new NotesController(mockRepo.Object);

            // Act
            var result = await controller.PutNotes(1, testNote);

            NoContentResult objectResult = result as NoContentResult;

            //Note objectResultValue = objectResult.Value as Note;
            // Assert
            //Assert.True(Assert.Equal(title,result.Result))
            Assert.Equal(204, objectResult.StatusCode);
            //Assert.True(objectResultValue.TrueForAll(x => x.Title == title));
            //Assert.Equal("Note 1", result.Result.Should().BeEquivalentTo())
        }
        public async Task PutProductTest()
        {
            // Arrange
            var     productsController = this.CreateProductsController();
            Product product            = new Product
            {
                Id          = 1,
                Name        = "Product",
                Price       = 275,
                Description = "Description",
                ImgUri      = new Uri("http\\\\web.com\\ghh.png", UriKind.RelativeOrAbsolute)
            };
            var expected = new NoContentResult();

            this.mockDataContext.Setup(m => m.PutProduct(product)).Returns(Task.FromResult((IActionResult)expected));
            // Act
            var result = await productsController.PutProduct(product).ConfigureAwait(false);

            // Assert
            Assert.Equal(expected, result);
            this.mockRepository.VerifyAll();
        }
        public void Delete_Should_delete_all_flights_return_statusCode_204()
        {
            // Arrange
            var flight1 = new FlightDTO
            {
                Number           = 1111,
                PointOfDeparture = "Lviv",
                DepartureTime    = new DateTime(2018, 07, 10, 18, 23, 0),
                Destination      = "London",
                DestinationTime  = new DateTime(2018, 07, 11, 18, 23, 0)
            };
            var flight2 = new FlightDTO
            {
                Number           = 2222,
                PointOfDeparture = "Lviv",
                DepartureTime    = new DateTime(2018, 07, 11, 18, 23, 0),
                Destination      = "Tokio",
                DestinationTime  = new DateTime(2018, 07, 12, 18, 0, 0)
            };

            var flightService = A.Fake <IFlightService>();

            A.CallTo(() => flightService.GetEntities()).Returns(new List <FlightDTO> {
                flight1, flight2
            });

            var flightsController = new FlightsController(flightService);

            //Act
            var actionResult = flightsController.Delete();

            //Assert
            Assert.NotNull(actionResult);

            NoContentResult result = actionResult as NoContentResult;

            Assert.NotNull(result);
            Assert.AreEqual(204, result.StatusCode);
        }
示例#29
0
        public async Task When_Payment_Is_Process_Then_Return_NoContentResult()
        {
            _mockPaymentsService.Setup(x => x.ProcessPayment(It.IsAny <PaymentRequest>()))
            .ReturnsAsync(true);

            var controller = new PaymentsController(_logger, _mockPaymentsService.Object, _mockBankService.Object);

            var paymentRequest = new PaymentRequest
            {
                CardNumber = "4242424242424242",
                Amount     = 32.56m,
                Currency   = "USD",
                Cvv        = "123",

                ExpiryMonth = DateTime.Now.Month,
                ExpiryYear  = DateTime.Now.Year
            };

            var expected = new NoContentResult();
            var actual   = await controller.ProcessPayment(paymentRequest);

            actual.Should().BeEquivalentTo(expected);
        }
        public void TestFullyUpdateAnExistingArtworkForAnExistingArtist(int artistId, int artworkId)
        {
            // Arrange
            ArtworkForUpdateDto artwork = new ArtworkForUpdateDto
            {
                Title             = "Updated - New Title",
                Year              = 2017,
                ShortDescription  = "Updated - Short Description",
                LongDescription   = "Updated - Long Description",
                ImageUrl          = "/images/Artworks/02-Vincent-van-Gogh/2017-New-Title.jpg",
                ImageThumbnailUrl = "/images/Artworks/02-Vincent-van-Gogh/2017-New-Title_tn.jpg",
                Source            = "www.wikipedia.org"
            };

            // Act
            IActionResult actionResult = _cutArtworks.UpdateArtwork(artistId, artworkId, artwork);

            // Assert
            Assert.NotNull(actionResult);
            NoContentResult result = actionResult as NoContentResult;

            Assert.NotNull(result);
            Assert.Equal(204, result.StatusCode);
        }
示例#31
0
        public IActionResult RemoveClient(string clientID)
        {
            IActionResult result;
            Guid          clientIDGuid;

            if (StringUtils.GuidTryDecode(clientID, out clientIDGuid))
            {
                Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
                if (client != null)
                {
                    BusinessLogicFactory.Clients.DeleteClient(client);
                    result = new NoContentResult();
                }
                else
                {
                    result = new NotFoundResult();
                }
            }
            else
            {
                result = new NotFoundResult();
            }
            return(result);
        }
 public IActionResult RemovePSKIdentity(string identity)
 {
     IActionResult result;
     Model.PSKIdentity pskIdentity = BusinessLogicFactory.Identities.GetPSKIdentity(identity);
     if (pskIdentity == null)
         result = new NotFoundResult();
     else
     {
         BusinessLogicFactory.Identities.SavePSKIdentity(pskIdentity, Model.TObjectState.Delete);
         result = new NoContentResult();
     }
     return result;
 }
 public IActionResult RemoveAccessKey(string key)
 {
     IActionResult result;
     Model.AccessKey accessKey = BusinessLogicFactory.AccessKeys.GetAccessKey(key);
     if (accessKey == null)
         result = new NotFoundResult();
     else
     {
         BusinessLogicFactory.AccessKeys.SaveAccessKey(accessKey, Model.TObjectState.Delete);
         result = new NoContentResult();
     }
     return result;
 }
 public IActionResult UpdateAccessKey(string key, [FromBody] ServiceModels.AccessKey accessKey)
 {
     IActionResult result;
     Model.AccessKey existingAccessKey = BusinessLogicFactory.AccessKeys.GetAccessKey(key);
     if (existingAccessKey == null)
         result = new NotFoundResult();
     else
     {
         existingAccessKey.Name = accessKey.Name;
         BusinessLogicFactory.AccessKeys.SaveAccessKey(existingAccessKey, Model.TObjectState.Update);
         result = new NoContentResult();
     }
     return result;
 }
        public IActionResult RemoveObjectInstance(string clientID, string definitionID, string instanceID)
        {
            IActionResult result;

            Guid definitionIDGuid, clientIDGuid;
            if (StringUtils.GuidTryDecode(definitionID, out definitionIDGuid) && StringUtils.GuidTryDecode(clientID, out clientIDGuid))
            {
                int organisationID = User.GetOrganisationID();
                Model.ObjectDefinition definition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, definitionIDGuid);
                if (definition != null)
                {
                    Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
                    if (client != null)
                    {
                        Model.Object instance = BusinessLogicFactory.Clients.GetObject(client, definition.ObjectDefinitionID, instanceID);
                        if (instance != null)
                        {
                            BusinessLogicFactory.Clients.SaveObject(client, instance, Model.TObjectState.Delete);
                            result = new NoContentResult();
                        }
                        else
                        {
                            result = new NotFoundResult();
                        }
                    }
                    else
                    {
                        result = new NotFoundResult();
                    }
                }
                else
                {
                    result = new NotFoundResult();
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return result;
        }
 public IActionResult RemoveObjectDefinition(string id)
 {
     IActionResult result;
     Guid objectDefinitionID;
     if (StringUtils.GuidTryDecode(id, out objectDefinitionID))
     {
         int organisationID = User.GetOrganisationID();
         Model.ObjectDefinition objectDefinition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, objectDefinitionID);
         if (objectDefinition == null)
             result = new NotFoundResult();
         else
         {
             if (!objectDefinition.OrganisationID.HasValue && (organisationID != 0))
                 result = new StatusCodeResult((int)System.Net.HttpStatusCode.Forbidden);
             else
             {
                 BusinessLogicFactory.ObjectDefinitions.SaveObjectDefinition(objectDefinition, Model.TObjectState.Delete);
                 result = new NoContentResult();
             }
         }
     }
     else
         result = new BadRequestResult();
     return result;
 }
 public IActionResult UpdateObjectDefinition(string id, [FromBody] ServiceModels.ObjectDefinition objectDefinition)
 {
     IActionResult result;
     Guid objectDefinitionID;
     if (StringUtils.GuidTryDecode(id, out objectDefinitionID))
     {
         int organisationID = User.GetOrganisationID();
         Model.ObjectDefinition existingObjectDefinition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, objectDefinitionID);
         if (existingObjectDefinition == null)
             result = new NotFoundResult();
         else
         {
             if (!existingObjectDefinition.OrganisationID.HasValue && (organisationID != 0))
                 result = new StatusCodeResult((int)System.Net.HttpStatusCode.Forbidden);
             else
             {
                 Model.ObjectDefinition updatedObjectDefinition = objectDefinition.ToModel();
                 updatedObjectDefinition.OrganisationID = User.GetOrganisationID();
                 BusinessLogicFactory.ObjectDefinitions.SaveObjectDefinition(updatedObjectDefinition, Model.TObjectState.Update);
                 result = new NoContentResult();
             }
         }
     }
     else
         result = new BadRequestResult();
     return result;
 }
        public IActionResult UpdateObjectInstance(string clientID, string definitionID, string instanceID)
        {
            IActionResult result;

            Guid definitionIDGuid, clientIDGuid;
            if (StringUtils.GuidTryDecode(definitionID, out definitionIDGuid) && StringUtils.GuidTryDecode(clientID, out clientIDGuid))
            {
                Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid);
                int organisationID = User.GetOrganisationID();
                Model.ObjectDefinition definition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, definitionIDGuid);
                if (definition != null)
                {
                    // TODO: add error handling around deserialisation.
                    List<Model.Property> executeProperties = new List<Model.Property>();
                    Model.Object lwm2mObject = new ServiceModels.ObjectInstance(definition, Request).Resource;
                    lwm2mObject.InstanceID = instanceID;
                    int index = 0;
                    while (index < lwm2mObject.Properties.Count)
                    {
                        Model.PropertyDefinition propertyDefinition = definition.GetProperty(lwm2mObject.Properties[index].PropertyDefinitionID);
                        if (propertyDefinition.Access == Model.TAccessRight.Execute)
                        {
                            executeProperties.Add(lwm2mObject.Properties[index]);
                            lwm2mObject.Properties.RemoveAt(index);
                        }
                        else
                        {
                            index++;
                        }
                    }
                    if (lwm2mObject.Properties.Count > 0)
                        BusinessLogicFactory.Clients.SaveObject(client, lwm2mObject, Model.TObjectState.Update);
                    if (executeProperties.Count > 0)
                    {
                        BusinessLogicFactory.Clients.Execute(client, lwm2mObject, executeProperties);
                    }
                    result = new NoContentResult();
                }
                else
                {
                    result = new BadRequestResult();
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return result;
        }
        public IActionResult UpdateSubscription(string subscriptionID, [FromBody] ServiceModels.Subscription subscription)
        {
            IActionResult result;
            Guid subscriptionIDGuid;
            if (StringUtils.GuidTryDecode(subscriptionID, out subscriptionIDGuid))
            {
                Model.Subscription subscriptionToUpdate = BusinessLogicFactory.Subscriptions.GetSubscription(subscriptionIDGuid);
                if (subscriptionToUpdate == null)
                    result = new NotFoundResult();
                else
                {
                    subscription.UpdateModel(subscriptionToUpdate);

                    if (!ExistingSubscriptionMatches(subscriptionToUpdate))
                    {
                        BusinessLogicFactory.Subscriptions.SaveSubscription(subscriptionToUpdate, TObjectState.Update);
                        result = new NoContentResult();
                    }
                    else
                    {
                        result = new StatusCodeResult((int)System.Net.HttpStatusCode.Conflict);
                    }
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return result;
        }
 public IActionResult RemoveSubscription(string subscriptionID)
 {
     IActionResult result;
     Guid subscriptionIDGuid;
     if (StringUtils.GuidTryDecode(subscriptionID, out subscriptionIDGuid))
     {
         Model.Subscription subscription = BusinessLogicFactory.Subscriptions.GetSubscription(subscriptionIDGuid);
         if (subscription == null)
             result = new NotFoundResult();
         else
         {
             BusinessLogicFactory.Subscriptions.SaveSubscription(subscription, TObjectState.Delete);
             result = new NoContentResult();
         }
     }
     else
     {
         result = new BadRequestResult();
     }
     return result;
 }