Exemple #1
0
 public void SaveDisclaimerType(List <dtoCallSection <dtoCallField> > sections, long idField, DisclaimerType dType)
 {
     if (UserContext.isAnonymous)
     {
         View.DisplaySessionTimeout();
     }
     else
     {
         CallForPaperType type        = View.CallType;
         long             idCall      = View.IdCall;
         Int32            idCommunity = View.IdCommunity;
         CallService.SaveSections(idCall, sections);
         Boolean saved = CallService.SaveDisclaimerType(idField, dType);
         if (!saved)
         {
             View.DisplayError(EditorErrors.EditingDisclaimerType);
         }
         else
         {
             if (View.CallType == CallForPaperType.CallForBids)
             {
                 View.SendUserAction(idCommunity, View.IdCallModule, idCall, ModuleCallForPaper.ActionType.EditDisclaimerType);
             }
             else
             {
                 View.SendUserAction(idCommunity, View.IdCallModule, idCall, ModuleRequestForMembership.ActionType.EditDisclaimerType);
             }
             View.ReloadEditor(RootObject.CallSubmissionEditorFieldRemoved(idField, type, idCall, idCommunity, View.PreloadView));
         }
     }
 }
        private async Task <bool> CheckDisclaimerAsync(string clientId, string lykkeEntityId, DisclaimerType type)
        {
            IDisclaimer requiresApprovalDisclaimer = (await _redisService.GetDisclaimersAsync())
                                                     .Where(x => x.LykkeEntityId == lykkeEntityId)
                                                     .Where(o => o.Type == type)
                                                     .Where(o => o.StartDate < DateTime.UtcNow)
                                                     .OrderByDescending(p => p.StartDate)
                                                     .FirstOrDefault();

            if (requiresApprovalDisclaimer == null)
            {
                return(false);
            }

            IReadOnlyList <IClientDisclaimer> clientDisclaimers = await _redisService.GetClientDisclaimersAsync(clientId);

            HashSet <string> approvedDisclaimers = clientDisclaimers
                                                   .Where(o => o.Approved)
                                                   .Select(o => o.DisclaimerId)
                                                   .ToHashSet();

            List <Task> tasks;

            if (approvedDisclaimers.Contains(requiresApprovalDisclaimer.Id))
            {
                if (requiresApprovalDisclaimer.ShowOnEachAction)
                {
                    tasks = new List <Task>
                    {
                        _clientDisclaimerRepository.DeleteAsync(clientId, requiresApprovalDisclaimer.Id),
                        _redisService.DeleteClientDisclaimerAsync(clientId, requiresApprovalDisclaimer.Id)
                    };

                    await Task.WhenAll(tasks);
                }

                return(false);
            }

            var clientDisclaimer = new ClientDisclaimer
            {
                ClientId     = clientId,
                DisclaimerId = requiresApprovalDisclaimer.Id,
                ApprovedDate = DateTime.UtcNow
            };

            tasks = new List <Task>
            {
                _clientDisclaimerRepository.InsertOrReplaceAsync(clientDisclaimer),
                _redisService.AddClientDisclaimerAsync(clientDisclaimer)
            };

            await Task.WhenAll(tasks);

            _log.Info("Client pending disclaimer added", new  { clientId, requiresApprovalDisclaimer.Id });

            return(true);
        }