/// <summary> /// Updates only labels for Answer set. /// </summary> /// <param name="customerId">The customer identifier.</param> /// <param name="answerSetId">The answer set identifier.</param> /// <param name="lowLabel">The low label.</param> /// <param name="midLabel">The mid label.</param> /// <param name="highLabel">The high label.</param> /// <returns></returns> public async Task <UpdateScaleAnswerSetLocalization> UpdateLabels( int customerId, Guid answerSetId, LowLabelScaleAnswerSetString lowLabel, MidLabelScaleAnswerSetString midLabel, HighLabelScaleAnswerSetString highLabel ) { var answerSet = await Get(customerId, answerSetId); if (answerSet == null) { return(UpdateScaleAnswerSetLocalization.NotFound); } // Low label. if (answerSet.LowLabelScaleAnswerSetStrings.All(l => l.Language != lowLabel.Language)) { //lowLabelRepository.Insert(lowLabel); answerSet.LowLabelScaleAnswerSetStrings.Add(lowLabel); } else { var dbLowLabel = answerSet.LowLabelScaleAnswerSetStrings .First(l => l.Language == lowLabel.Language); UpdateLabelFields(lowLabel, dbLowLabel); } // Mid label. if (midLabel != null && answerSet.MidLabelScaleAnswerSetStrings.All(l => l.Language != midLabel.Language)) { //midLabelRepository.Insert(midLabel); answerSet.MidLabelScaleAnswerSetStrings.Add(midLabel); } if (midLabel != null && answerSet.MidLabelScaleAnswerSetStrings.Any(l => l.Language == midLabel.Language)) { var dbMidLabel = answerSet.MidLabelScaleAnswerSetStrings .First(l => l.Language == midLabel.Language); UpdateLabelFields(midLabel, dbMidLabel); } // High label. if (answerSet.HighLabelScaleAnswerSetStrings.All(l => l.Language != highLabel.Language)) { //highLabelRepository.Insert(highLabel); answerSet.HighLabelScaleAnswerSetStrings.Add(highLabel); } else { var dbHighLabel = answerSet.HighLabelScaleAnswerSetStrings .First(l => l.Language == highLabel.Language); UpdateLabelFields(highLabel, dbHighLabel); } scaleAnswerSetRepository.Update(answerSet); unitOfWork.SaveAsync(); return(UpdateScaleAnswerSetLocalization.Success); }
/// <summary> /// Updates the localized strings. /// </summary> /// <param name="customerId">The customer identifier.</param> /// <param name="scaleAnswerSetId">The scale answer set identifier.</param> /// <param name="model">The model.</param> /// <param name="language">The language.</param> /// <returns></returns> public async Task <UpdateScaleAnswerSetLocalization> UpdateLocalizedStrings( int customerId, Guid scaleAnswerSetId, UpdateScaleAnswerSetLocalizedRequestDto model, string language ) { var lowLabel = await MapUpdatingLabelToLocalizedString <LowLabelScaleAnswerSetString>(model.LowLabel, language); MidLabelScaleAnswerSetString midLabel = null; if (model.MidLabel != null && model.MidLabel.Value != null) { midLabel = await MapUpdatingLabelToLocalizedString <MidLabelScaleAnswerSetString>(model.MidLabel, language); } var highLabel = await MapUpdatingLabelToLocalizedString <HighLabelScaleAnswerSetString>(model.HighLabel, language); var status = await scaleAnswerSetService.UpdateLabels(customerId, scaleAnswerSetId, lowLabel, midLabel, highLabel); return(status); }
/// <summary> /// Updates the specified answer set. /// </summary> /// <param name="customerId">The customer identifier.</param> /// <param name="scaleAnswerSetId">The scale answer set identifier.</param> /// <param name="answerSet">The answer set.</param> /// <returns></returns> public async Task <UpdateScaleAnswerSetStatus> Update(int customerId, Guid scaleAnswerSetId, ScaleAnswerSet answerSet) { var dbEntity = await Get(customerId, scaleAnswerSetId); if (dbEntity == null) { return(UpdateScaleAnswerSetStatus.NotFound); } dbEntity.CustomerId = answerSet.CustomerId; dbEntity.Tags.RemoveRange(dbEntity.Tags.ToList()); dbEntity.Tags.AddRange(answerSet.Tags.ToList()); dbEntity.Name = answerSet.Name; dbEntity.HighValue = answerSet.HighValue; dbEntity.LowValue = answerSet.LowValue; var lowLabel = answerSet.LowLabelScaleAnswerSetStrings.First(); var midLabel = answerSet.MidLabelScaleAnswerSetStrings.FirstOrDefault(); var highLabel = answerSet.HighLabelScaleAnswerSetStrings.First(); var dbLowLabel = dbEntity.LowLabelScaleAnswerSetStrings.FirstOrDefault( l => l.Language == lowLabel.Language); var dbHighLabel = dbEntity.HighLabelScaleAnswerSetStrings.FirstOrDefault( l => l.Language == highLabel.Language); UpdateScaleAnswerSetStatus status = 0; if (dbLowLabel == null) { status = status | UpdateScaleAnswerSetStatus.LowLabelLanguageNotMatch; } if (dbHighLabel == null) { status = status | UpdateScaleAnswerSetStatus.HighLabelLanguageNotMatch; } if (status > 0) { return(status); } if (midLabel != null) { var dbMidLabel = dbEntity.MidLabelScaleAnswerSetStrings .FirstOrDefault(l => l.Language == midLabel.Language); if (dbMidLabel == null) { dbMidLabel = new MidLabelScaleAnswerSetString(); UpdateLabelFields(midLabel, dbMidLabel); dbEntity.MidLabelScaleAnswerSetStrings.Add(dbMidLabel); } else { UpdateLabelFields(midLabel, dbMidLabel); } } UpdateLabelFields(lowLabel, dbLowLabel); UpdateLabelFields(highLabel, dbHighLabel); scaleAnswerSetRepository.Update(dbEntity); await unitOfWork.SaveAsync(); return(UpdateScaleAnswerSetStatus.Success); }