/// <summary> /// Initializes program entity using request data. Saves entities in database. /// </summary> /// <param name="customerId">The customer identifier.</param> /// <param name="programCreateDto">The program create dto.</param> /// <returns></returns> public async Task <OperationResultDto <ProgramBriefResponseDto, CreateUpdateProgramStatus> > CreateProgram( int customerId, ProgramRequestDto programCreateDto ) { var newProgram = await BuildProgram(customerId, programCreateDto); if (newProgram.Status != CreateUpdateProgramStatus.Success) { return(new OperationResultDto <ProgramBriefResponseDto, CreateUpdateProgramStatus>() { Status = newProgram.Status }); } var createProgramResponse = await programService.Create(newProgram.Content); var respoDto = Mapper.Map <ProgramBriefResponseDto>(createProgramResponse.Content); await globalSearchCacheHelper.AddOrUpdateEntry(customerId, Mapper.Map <Program, SearchProgramResponseDto>(createProgramResponse.Content)); await tagsSearchCacheHelper.AddOrUpdateTags(customerId, createProgramResponse.Content.Tags.Select(t => t.Name).ToList()); var unusedTags = await tagsService.RemoveUnusedTags(customerId); await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags); return(new OperationResultDto <ProgramBriefResponseDto, CreateUpdateProgramStatus>() { Status = newProgram.Status, Content = respoDto }); }
/// <summary> /// Creates the program. /// </summary> /// <param name="token">The token.</param> /// <param name="customerId">The customer identifier.</param> /// <param name="programId">Id of existed program.</param> /// <param name="programDto">The program dto.</param> /// <returns></returns> public async Task UpdateProgram(string token, int customerId, Guid programId, ProgramRequestDto programDto) { var url = string.Format("/api/{0}/programs/{1}", customerId, programId); await this.apiClient.SendRequestAsync(url, programDto, Method.PUT, null, token); }
/// <summary> /// Updates the program. /// </summary> /// <param name="customerId"></param> /// <param name="programId">The identifier.</param> /// <param name="updateProgramDto">The update program dto.</param> /// <returns></returns> public async Task <CreateUpdateProgramStatus> UpdateProgram( int customerId, Guid programId, ProgramRequestDto updateProgramDto ) { var updatedProgram = await BuildProgram(customerId, updateProgramDto); if (updatedProgram.Status != CreateUpdateProgramStatus.Success) { return(updatedProgram.Status); } var result = await programService.Update(customerId, programId, updatedProgram.Content); updatedProgram.Content.Id = programId; await globalSearchCacheHelper.AddOrUpdateEntry(customerId, Mapper.Map <Program, SearchProgramResponseDto>(updatedProgram.Content)); await tagsSearchCacheHelper.AddOrUpdateTags(customerId, updatedProgram.Content.Tags.Select(t => t.Name).ToList()); var unusedTags = await tagsService.RemoveUnusedTags(customerId); await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags); return(result); }
public async Task <IHttpActionResult> CreateProgram( int customerId, ProgramRequestDto request ) { var result = await controllerHelper.CreateProgram(customerId, request); if (result.Status != CreateUpdateProgramStatus.Success) { return(Content( HttpStatusCode.BadRequest, new ErrorResponseDto() { Error = ErrorCode.InvalidRequest, Message = ErrorCode.InvalidRequest.Description(), Details = result.Status.Description() } )); } return(Created( new Uri(Request.RequestUri, result.Content.Id.ToString()), new PostResponseDto <Guid> { Id = result.Content.Id } )); }
/// <summary> /// Send request to HL to create new program. /// </summary> /// <param name="programModel"></param> /// <returns></returns> public async Task <CreateProgramResultDto> CreateProgram(ProgramRequestDto programModel) { var programDto = Mapper.Map <ProgramRequestDto>(programModel); var token = this.authDataStorage.GetToken(); var createProgramResult = await healthLibraryService.CreateProgram(token, this.customerContext.Customer.Id, programDto); return(createProgramResult); }
/// <summary> /// Generates Program instance using data of ProgramRequestDto. /// </summary> /// <param name="customerId">The customer identifier.</param> /// <param name="programDto">The program dto.</param> /// <returns></returns> private async Task <OperationResultDto <Program, CreateUpdateProgramStatus> > BuildProgram(int customerId, ProgramRequestDto programDto) { var resultProgram = Mapper.Map <Program>(programDto); resultProgram.CustomerId = customerId; resultProgram.Tags = await tagsService.BuildTagsList(customerId, programDto.Tags); resultProgram.ProgramElements = new List <ProgramElement>(); foreach (var programElementDto in programDto.ProgramElements) { var programElement = Mapper.Map <ProgramElement>(programElementDto); var protocol = await this.protocolService.GetProtocol(customerId, programElement.ProtocolId); if (protocol == null) { return(new OperationResultDto <Program, CreateUpdateProgramStatus>() { Content = null, Status = CreateUpdateProgramStatus.InvalidProtocolId }); } foreach (var programDayElementDto in programElementDto.ProgramDayElements) { var programDayElement = BuildProgramDayElement(programDayElementDto, resultProgram.Recurrences); if (programDayElement == null) { return(new OperationResultDto <Program, CreateUpdateProgramStatus>() { Status = CreateUpdateProgramStatus.InvalidRecurrenceReferenceProvided }); } programElement.ProgramDayElements.Add(programDayElement); resultProgram.ProgramDayElements.Add(programDayElement); } resultProgram.ProgramElements.Add(programElement); } if (resultProgram.Recurrences != null) { resultProgram.Recurrences.Each(r => r.Id = default(Guid)); } return(new OperationResultDto <Program, CreateUpdateProgramStatus>() { Status = CreateUpdateProgramStatus.Success, Content = resultProgram }); }
/// <summary> /// Send request to HL to update program. /// </summary> /// <param name="id">Id of program to update.</param> /// <param name="programModel"></param> /// <returns></returns> public async Task UpdateProgram(Guid id, ProgramRequestDto programModel) { var token = this.authDataStorage.GetToken(); await healthLibraryService.UpdateProgram(token, this.customerContext.Customer.Id, id, programModel); }
public async Task <CreateProgramResultDto> CreateProgram(string token, int customerId, ProgramRequestDto programDto) { var url = string.Format("/api/{0}/programs", customerId); return(await this.apiClient.SendRequestAsync <CreateProgramResultDto>(url, programDto, Method.POST, null, token)); }
public async Task <IHttpActionResult> UpdateProgram(int customerId, Guid programId, ProgramRequestDto request) { var updateResult = await controllerHelper.UpdateProgram(customerId, programId, request); if (updateResult.HasFlag(CreateUpdateProgramStatus.NotFound)) { return(Content( HttpStatusCode.NotFound, new ErrorResponseDto() { Error = ErrorCode.InvalidRequest, Message = ErrorCode.InvalidRequest.Description(), Details = CreateUpdateProgramStatus.NotFound.Description() } )); } return(StatusCode(HttpStatusCode.NoContent)); }