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));
            }
        }
示例#2
0
 public DomainOperationVo(DomainActionPerformed action, T entity)
 {
     Action = action;
     Entity = entity;
 }