public IActionResult Update(ProtocolViewModel protocol)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                protocolService.UpdateProtocol(ProtocolMapper.MapToDomainModel(protocol));
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Updates the protocol.
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="protocolId">The protocol identifier.</param>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <CreateUpdateProtocolStatus> UpdateProtocol(
            int customerId,
            Guid protocolId,
            UpdateProtocolRequestDto request
            )
        {
            #region Step 1 - Client IDs validation

            var validationResult = PerformValidationStep1(request);

            if (!validationResult.HasFlag(CreateUpdateProtocolStatus.Success))
            {
                return(validationResult);
            }

            #endregion

            #region Step 2 - Remaining Validation which can be made only after successfuly passed step 1

            validationResult = await PerformValidationStep2(request);

            if (!validationResult.HasFlag(CreateUpdateProtocolStatus.Success))
            {
                return(validationResult);
            }

            #endregion

            var updatedProtocol = await BuildProtocol(customerId, request);

            var result = await protocolService.UpdateProtocol(customerId, protocolId, updatedProtocol);

            updatedProtocol.Id = protocolId;
            await globalSearchCacheHelper.AddOrUpdateEntry(customerId, Mapper.Map <Protocol, SearchEntryDto>(updatedProtocol));

            await tagsSearchCacheHelper.AddOrUpdateTags(customerId, updatedProtocol.Tags.Select(t => t.Name).ToList());

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);

            return(result);
        }