public async Task <ChoiceGetData> PostAsync(ChoicePostData data) { using var connection = authService.Connection; var optionsArray = data.Options.Split(",").Select(o => o.Trim()).ToArray(); if (optionsArray.Length < 2) { throw new Exception("At least 2 options are required."); } string optionsString = string.Join(",", optionsArray); var entity = new ChoiceEntity() { Name = data.Name.Trim(), Options = optionsString, UserId = authService.UserId }; var context = new DatabaseContext(connection); await context.AddAsync(entity); await context.SaveChangesAsync(); await connection.CloseAsync(); return(CreateGetDataFromEntity(entity)); }
private static ChoiceGetData CreateGetDataFromEntity(ChoiceEntity entity) { return(new ChoiceGetData() { Id = entity.Id, Name = entity.Name, Options = entity.Options.Split(","), DefinitiveOption = entity.DefinitiveOption }); }
public void SendingCallJSONCategoryChoiceDetail_JSONConverted() { // Arrange var testString = "Test"; var detail = new DetailEntity() { DetailId = Guid.NewGuid().ToString(), Name = "Mælk", }; var choice = new ChoiceEntity() { ChoiceId = Guid.NewGuid().ToString(), Name = "Kaffe", Details = new List <DetailEntity> { detail } }; var category = new CategoryEntity() { CategoryId = Guid.NewGuid().ToString(), Name = "Dinmor", //Picture = "http://multimedia.pol.dk/archive/00537/ITALY_CLONED_CHAMPI_537998a.jpg", Choices = new List <ChoiceEntity> { choice } }; CallEntity callEntity = CallWrapper.WrapCall(CPRNUMMER, CallUtil.StatusCode.Active, category, choice, detail); try { //Act PatientCall call = new PatientCall(); var callId = call.MakeCall(callEntity); Assert.IsTrue(!String.IsNullOrEmpty(callId)); } catch (Exception ex) { Assert.Fail("Status Code not OK " + ex.Message); } }
public void UpdatingCallJSON_CalledUpdated() { //Arrange // Arrange var testString = "Test"; var choice = new ChoiceEntity() { ChoiceId = Guid.NewGuid().ToString(), Name = "Morfin" }; var category = new CategoryEntity() { CategoryId = Guid.NewGuid().ToString(), Name = "Smertestillende", //Picture = "http://multimedia.pol.dk/archive/00537/ITALY_CLONED_CHAMPI_537998a.jpg", Choices = new List <ChoiceEntity> { choice } }; CallEntity callEntity = CallWrapper.WrapCall(CPRNUMMER, CallUtil.StatusCode.Active, category, choice, null); //Act PatientCall call = new PatientCall(); try { callEntity._id = "5641c5dd02a93d27a8910f9c"; callEntity.Status = (int)CallUtil.StatusCode.Canceled; call.UpdateCall(callEntity); } catch (Exception e) { // Assert Assert.Fail("No calls has been updated"); } }
/// <summary> /// Wrapper en Category, Choice og/eller Detail til et kald sammen med Patients CPR-nr og en Status kode på kaldet(Afventende, Udført, Fortrudt) /// </summary> /// <param name="cprnr">CPR-nr for Patient</param> /// <param name="status">Status kode(Active, Completed, Canceled) på kaldet</param> /// <param name="categoryEntity">Kategorien</param> /// <param name="choiceEntity">Valget</param> /// <param name="detailEntity">Tilebør</param> /// <returns>Returner et objekt der anses som et kald, klar til at blive sendt afsted til Web API</returns> public static CallEntity WrapCall(String cprnr, CallUtil.StatusCode status, CategoryEntity categoryEntity, ChoiceEntity choiceEntity = null, DetailEntity detailEntity = null) { var callEntity = new CallEntity(); /* Non-nullable values */ //callEntity._id = Guid.NewGuid().ToString(); callEntity.PatientCPR = cprnr; callEntity.Status = (int)status; callEntity.Category = categoryEntity.Name; /* Nullable values*/ /* * if (categoryEntity.Picture != null) * { * callEntity.Picture = categoryEntity.Picture; * } */ if (choiceEntity != null) { callEntity.Choice = choiceEntity.Name; } /* Nullable values*/ if (detailEntity != null) { callEntity.Detail = detailEntity.Name; } return(callEntity); }
public List <CategoryEntity> GetCategoriesTESTDATA() { // TEST DATA var categoryEntities = new List <CategoryEntity>(); // CATEGORY -> CHOICES -> DETAILS var d1 = new DetailEntity() { DetailId = Guid.NewGuid().ToString(), Name = "Mælk", }; var d2 = new DetailEntity() { DetailId = Guid.NewGuid().ToString(), Name = "Sukker" }; var d3 = new DetailEntity() { DetailId = Guid.NewGuid().ToString(), Name = "Sort kaffe" }; var d4 = new DetailEntity() { DetailId = Guid.NewGuid().ToString(), Name = "Sukkerfri" }; var d5 = new DetailEntity() { DetailId = Guid.NewGuid().ToString(), Name = "Tun og æg" }; var d6 = new DetailEntity() { DetailId = Guid.NewGuid().ToString(), Name = "Skinke og ost" }; var ch1 = new ChoiceEntity() { ChoiceId = Guid.NewGuid().ToString(), Name = "Kaffe", Details = new List <DetailEntity> { d1, d2, d3 } // 1-M }; var ch2 = new ChoiceEntity() { ChoiceId = Guid.NewGuid().ToString(), Name = "Cola", Details = new List <DetailEntity> { d2, d4 } // 1-M }; d1.Choices = new List <ChoiceEntity> { ch1 }; d2.Choices = new List <ChoiceEntity> { ch1, ch2 }; // M-M d3.Choices = new List <ChoiceEntity> { ch1 }; d4.Choices = new List <ChoiceEntity> { ch2 }; var ch3 = new ChoiceEntity() { ChoiceId = Guid.NewGuid().ToString(), Name = "Sandwich", Details = new List <DetailEntity> { d5, d6 } }; d5.Choices = new List <ChoiceEntity> { ch3 }; d6.Choices = new List <ChoiceEntity> { ch3 }; var cat1 = new CategoryEntity() { CategoryId = Guid.NewGuid().ToString(), Name = "Mad/Drikke", //Picture = "http://multimedia.pol.dk/archive/00537/ITALY_CLONED_CHAMPI_537998a.jpg", Choices = new List <ChoiceEntity> { ch1, ch2, ch3 } }; ch1.CategoryId = cat1.CategoryId; ch2.CategoryId = cat1.CategoryId; categoryEntities.Add(cat1); // CATEGORY -> CHOICES var ch4 = new ChoiceEntity() { ChoiceId = Guid.NewGuid().ToString(), Name = "Morfin" }; var ch5 = new ChoiceEntity() { ChoiceId = Guid.NewGuid().ToString(), Name = "Panodil" }; var cat2 = new CategoryEntity() { CategoryId = Guid.NewGuid().ToString(), Name = "Smertestillende", //Picture = "http://multimedia.pol.dk/archive/00537/ITALY_CLONED_CHAMPI_537998a.jpg", Choices = new List <ChoiceEntity> { ch4, ch5 } }; ch2.CategoryId = cat2.CategoryId; categoryEntities.Add(cat2); // CATEGORY -> OBS EMPTY CHOICE var cat3 = new CategoryEntity() { CategoryId = Guid.NewGuid().ToString(), Name = "Toilet", //Picture = "http://multimedia.pol.dk/archive/00537/ITALY_CLONED_CHAMPI_537998a.jpg", }; ch3.CategoryId = cat3.CategoryId; categoryEntities.Add(cat3); return(categoryEntities); }