public OperationResultVo SaveEntry(Guid currentUserId, Guid projectId, bool currentUserIsOwner, bool currentUserHelped, LocalizationEntryViewModel vm) { int pointsEarned = 0; try { LocalizationEntry entry = mapper.Map <LocalizationEntry>(vm); DomainActionPerformed actionPerformed = translationDomainService.AddEntry(projectId, entry); if (actionPerformed == DomainActionPerformed.None) { return(new OperationResultVo("Another user already sent that translation!")); } if (!currentUserIsOwner && actionPerformed == DomainActionPerformed.Create) { pointsEarned += gamificationDomainService.ProcessAction(currentUserId, PlatformAction.LocalizationHelp); } unitOfWork.Commit(); vm.Id = entry.Id; if (!currentUserHelped && !currentUserIsOwner) { bool badgeUpdated = gamificationDomainService.SetBadgeOccurence(currentUserId, BadgeType.Babel, projectId); if (badgeUpdated) { unitOfWork.Commit(); } } UserProfile profile = GetCachedProfileByUserId(entry.UserId); vm.AuthorName = profile.Name; return(new OperationResultVo <LocalizationEntryViewModel>(vm, pointsEarned, "Translation saved!")); } catch (Exception ex) { return(new OperationResultVo(ex.Message)); } }
public IActionResult SaveTranslation(Guid projectId, bool currentUserIsOwner, bool currentUserHelped, LocalizationEntryViewModel vm) { try { vm.UserId = CurrentUserId; OperationResultVo result = translationAppService.SaveEntry(CurrentUserId, projectId, currentUserIsOwner, currentUserHelped, vm); if (result.Success) { OperationResultVo <LocalizationEntryViewModel> castResult = result as OperationResultVo <LocalizationEntryViewModel>; return(Json(castResult)); } else { return(Json(result)); } } catch (Exception ex) { return(Json(new OperationResultVo(ex.Message))); } }