//public dtoAdvStepContainer(Domain.AdvStep step) //{ // Id = step.Id; // Name = step.Name; // Order = step.Order; // Status = step.Status; // CallId = (step.Call != null) ? step.Call.Id : -1; // if(step.Commissions != null && step.Commissions.Any()) // { // Commissions = (from Domain.AdvCommission comm in step.Commissions.OrderByDescending(c => c.IsMaster).ThenBy(c => c.Name).ToList() // select new dtoAdvCommissionContainer(comm)).ToList(); // } //} /// <summary> /// Costruttore da oggetti dominio /// </summary> /// <param name="step">Step di riferimento</param> /// <param name="userId">Id Utente (per calcolo permessi)</param> public dtoAdvStepContainer(Domain.AdvStep step, int userId, int creatorId) { Id = step.Id; Name = step.Name; Order = step.Order; Status = step.Status; CallId = (step.Call != null) ? step.Call.Id : -1; StepPermission = GenericStepPermission.none; if (step.Commissions != null) // && step.Commissions.Any()) { //Comm.Criteria.Select(bc => new Eval.dtoCriterion(bc)).OrderBy(c => c.DisplayOrder).ThenBy(c => c.Name).ToList(); Commissions = step.Commissions.Select(cm => new dtoAdvCommissionContainer(cm, userId)).OrderByDescending(c => c.IsMaster).ThenBy(c => c.Name).ToList(); StepPermission = GenericStepPermission.none; if (Commissions.Any(cm => (cm.GenericPermission & GenericStepPermission.MainPresident) == GenericStepPermission.MainPresident)) { StepPermission |= GenericStepPermission.MainPresident; } if (Commissions.Any(cm => (cm.GenericPermission & GenericStepPermission.MainSecretary) == GenericStepPermission.MainSecretary)) { StepPermission |= GenericStepPermission.MainSecretary; } if (Commissions.Any(cm => (cm.GenericPermission & GenericStepPermission.President) == GenericStepPermission.President)) { StepPermission |= GenericStepPermission.President; } if (Commissions.Any(cm => (cm.GenericPermission & GenericStepPermission.Secretary) == GenericStepPermission.Secretary)) { StepPermission |= GenericStepPermission.Secretary; } if (Commissions.Any(cm => (cm.GenericPermission & GenericStepPermission.Member) == GenericStepPermission.Member)) { StepPermission |= GenericStepPermission.Member; } } if (creatorId > 0 && creatorId == userId) { StepPermission |= GenericStepPermission.MainPresident; StepPermission |= GenericStepPermission.MainSecretary; StepPermission |= GenericStepPermission.President; StepPermission |= GenericStepPermission.Secretary; } }
/// <summary> /// Method thats build the model with the Commissions for a Period /// </summary> /// <param name="idPeriod"></param> /// <returns></returns> public IEnumerable<CommissionModel> MontaModel(string idPeriod) { try { if (!String.IsNullOrWhiteSpace(idPeriod)) { var idPeriodo = Convert.ToInt32(idPeriod); var period = new WS.Period.Period().Get(Settings.AutenticationKeyEarningSystem, idPeriodo); var dtInicio = period != null ? period.DataInicio : DateTime.MinValue; var dtTermino = period != null ? period.DataTermino : DateTime.MaxValue; var promoter = new WS.Promoter.Promoter().GetPromoter( Settings.AutenticationKeyEarningSystem, RetornaidCliente()); if (promoter != null) { //Retorna as comissões var commissions = new Commissions().SelectFiltered( Settings.AutenticationKeyEarningSystem, dtInicio, dtTermino, promoter.IdPromoter); var commissionsGroup = (from c in commissions group c by c.Pedido.IdCliente into g select new CommissionModel { Cliente_Pedido = g.Select(m => m.Cliente_Pedido).FirstOrDefault(), Cliente = g.Select(m => m.Cliente).FirstOrDefault(), Nivel = g.Select(m => m.Nivel).FirstOrDefault(), ValorComissao = g.Sum(m => m.ValorComissao), ValorPedido = g.Sum(m => m.ValorPedido) }).ToArray(); return commissions.Any() ? commissionsGroup : new CommissionModel[0]; } } } catch (Exception ex) { LogService.Log("GS.CommissionController.Listing() :: Exception : ", ex); } return new CommissionModel[0]; }