Ejemplo n.º 1
0
 public ImportPolicy(DtoPolicyExport export)
 {
     _export        = export;
     _policyService = new ServicePolicy();
     _policy        = new EntityPolicy();
     _uow           = new UnitOfWork();
 }
Ejemplo n.º 2
0
        public EntityPolicy Insert(EntityPolicy Poliza)
        {
            var          objRepository = new RepositoryPolicy();
            EntityPolicy data          = new EntityPolicy()
            {
                PK_PolicyID    = 0,
                FK_OrderID     = Poliza.FK_OrderID,
                FK_ClientID    = Poliza.FK_ClientID,
                FK_EmployeeID  = Poliza.FK_EmployeeID,
                FK_QuotationID = Poliza.FK_QuotationID,
                FK_ProductID   = Poliza.FK_ProductID,
                FK_ShopPlace   = Poliza.FK_ShopPlace,
                IDPolicy       = Poliza.IDPolicy,
                PolicyPrice    = Poliza.PolicyPrice,
                Coin           = Poliza.Coin,
                SalesOrg       = Poliza.SalesOrg,
                ccGroup        = Poliza.ccGroup,
                SerialNumber   = Poliza.SerialNumber,
                PriceList      = Poliza.PriceList,
                MaterialGroup4 = Poliza.MaterialGroup4,
                GuarantyStart  = Poliza.GuarantyStart,
                GuarantyEnd    = Poliza.GuarantyEnd,
                PolicyDate     = Poliza.PolicyDate,
                Status         = true,
                CreateDate     = DateTime.UtcNow.ToLocalTime(),
                ModifyDate     = DateTime.UtcNow.ToLocalTime()
            };

            data = objRepository.Insert(data);
            return(data);
        }
Ejemplo n.º 3
0
 protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);
     RequiresAuthorization(AuthorizationStrings.PolicyRead);
     Policy = !string.IsNullOrEmpty(Request.QueryString["policyId"])
        ? Call.PolicyApi.Get(Convert.ToInt32(Request.QueryString["policyId"]))
        : null;
 }
        public void TestCustomersIncludeOrders()
        {
            var policy = new EntityPolicy();

            policy.IncludeWith <Customer>(c => c.Orders);
            Northwind nw = new Northwind(this.GetProvider().WithPolicy(policy));

            TestQuery(
                nw.Customers
                );
        }
Ejemplo n.º 5
0
        public void TestCustomersIncludeOrdersDeferred()
        {
            var policy = new EntityPolicy();

            policy.IncludeWith <Customer>(c => c.Orders, true);
            Northwind nw = new Northwind(this.provider.New(policy));

            TestQuery(
                nw.Customers
                );
        }
Ejemplo n.º 6
0
        public void TestCustomersIncludeOrdersAndDetails()
        {
            var policy = new EntityPolicy();

            policy.IncludeWith <Customer>(c => c.Orders);
            policy.IncludeWith <Order>(o => o.Details);
            Northwind nw = new Northwind(this.provider.New(policy));

            TestQuery(
                nw.Customers
                );
        }
Ejemplo n.º 7
0
        public DtoPolicyExport Export(DtoPolicyExportGeneral exportInfo)
        {
            _policy = _policyService.GetPolicy(exportInfo.PolicyId);
            if (_policy == null)
            {
                return(null);
            }

            var validationResult = new ValidatePolicy().Validate(exportInfo.PolicyId);

            if (!validationResult.Success)
            {
                return(null);
            }

            CopyPolicy(exportInfo);

            var policyModules = _policyService.SearchAssignedPolicyModules(exportInfo.PolicyId, _filter);

            foreach (var policyModule in policyModules.OrderBy(x => x.Name))
            {
                if (policyModule.ModuleType == EnumModule.ModuleType.Command)
                {
                    CopyCommandModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.FileCopy)
                {
                    CopyFileCopyModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Script)
                {
                    CopyScriptModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Printer)
                {
                    CopyPrinterModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Software)
                {
                    CopySoftwareModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Wupdate)
                {
                    CopyWuModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Message)
                {
                    CopyMessageModule(policyModule);
                }
            }

            return(_policyExport);
        }
Ejemplo n.º 8
0
        public void TestCustomersIncludeOrdersViaConstructorOnly()
        {
            var mapping = new AttributeMapping(typeof(NorthwindX));
            var policy  = new EntityPolicy();

            policy.IncludeWith <CustomerX>(c => c.Orders);
            NorthwindX nw = new NorthwindX(this.provider.New(policy).New(mapping));

            TestQuery(
                nw.Customers
                );
        }
Ejemplo n.º 9
0
        public void TestCustomersWhereIncludeOrders()
        {
            var policy = new EntityPolicy();

            policy.IncludeWith <Customer>(c => c.Orders);
            Northwind nw = new Northwind(this.provider.New(policy));

            TestQuery(
                from c in nw.Customers
                where c.City == "London"
                select c
                );
        }
        public void TestCustomersWhereIncludeOrdersAndDetails()
        {
            var policy = new EntityPolicy();

            policy.IncludeWith <Customer>(c => c.Orders);
            policy.IncludeWith <Order>(o => o.Details);
            Northwind nw = new Northwind(this.GetProvider().WithPolicy(policy));

            TestQuery(
                from c in nw.Customers
                where c.City == "London"
                select c
                );
        }
Ejemplo n.º 11
0
        public DtoClientPolicy Create(int policyId)
        {
            _policy = _policyService.GetPolicy(policyId);
            Policy();
            DtoModuleSearchFilter filter = new DtoModuleSearchFilter();

            filter.IncludeCommand  = true;
            filter.IncludeFileCopy = true;
            filter.IncludePrinter  = true;
            filter.IncludeScript   = true;
            filter.IncludeSoftware = true;
            filter.IncludeWu       = true;
            filter.IncludeMessage  = true;
            filter.Limit           = Int32.MaxValue;
            var policyModules = _policyService.SearchAssignedPolicyModules(policyId, filter);

            foreach (var policyModule in policyModules.OrderBy(x => x.Name))
            {
                if (policyModule.ModuleType == EnumModule.ModuleType.Command)
                {
                    CommandModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.FileCopy)
                {
                    FileCopyModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Script)
                {
                    ScriptModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Printer)
                {
                    PrinterModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Software)
                {
                    SoftwareModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Wupdate)
                {
                    WuModule(policyModule);
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Message)
                {
                    MessageModule(policyModule);
                }
            }

            return(_clientPolicy);
        }
Ejemplo n.º 12
0
        public DtoActionResult Post(EntityPolicy policy)
        {
            var result = _policyServices.AddPolicy(policy);

            if (result.Success)
            {
                var auditLog = new EntityAuditLog();
                auditLog.ObjectType = "Policy";
                auditLog.ObjectId   = result.Id;
                auditLog.ObjectName = policy.Name;
                auditLog.ObjectJson = JsonConvert.SerializeObject(policy);
                auditLog.UserId     = _userId;
                auditLog.AuditType  = EnumAuditEntry.AuditType.Create;
                _auditLogService.AddAuditLog(auditLog);
            }
            return(result);
        }
Ejemplo n.º 13
0
        public DtoActionResult AddPolicy(EntityPolicy policy)
        {
            policy.Guid = Guid.NewGuid().ToString();
            var validationResult = ValidatePolicy(policy, true);
            var actionResult     = new DtoActionResult();

            if (validationResult.Success)
            {
                _uow.PolicyRepository.Insert(policy);
                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = policy.Id;
            }
            else
            {
                actionResult.ErrorMessage = validationResult.ErrorMessage;
            }

            return(actionResult);
        }
Ejemplo n.º 14
0
        public DtoActionResult UpdatePolicy(EntityPolicy policy)
        {
            var u = GetPolicy(policy.Id);

            if (u == null)
            {
                return new DtoActionResult {
                           ErrorMessage = "Policy Not Found", Id = 0
                }
            }
            ;
            var activePolicy = GetActivePolicy(policy.Id);

            if (activePolicy != null)
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = "Active Policies Cannot Be Updated.  You Must Deactivate It First."
                       }
            }
            ;
            var validationResult = ValidatePolicy(policy, false);
            var actionResult     = new DtoActionResult();

            if (validationResult.Success)
            {
                _uow.PolicyRepository.Update(policy, policy.Id);

                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = policy.Id;
            }
            else
            {
                actionResult.ErrorMessage = validationResult.ErrorMessage;
            }

            return(actionResult);
        }
Ejemplo n.º 15
0
        public DtoActionResult Put(int id, EntityPolicy policy)
        {
            policy.Id = id;
            var result = _policyServices.UpdatePolicy(policy);

            if (result == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            if (result.Success)
            {
                var auditLog = new EntityAuditLog();
                auditLog.ObjectType = "Policy";
                auditLog.ObjectId   = result.Id;
                auditLog.ObjectName = policy.Name;
                auditLog.ObjectJson = JsonConvert.SerializeObject(policy);
                auditLog.UserId     = _userId;
                auditLog.AuditType  = EnumAuditEntry.AuditType.Update;
                _auditLogService.AddAuditLog(auditLog);
            }
            return(result);
        }
Ejemplo n.º 16
0
        private DtoValidationResult ValidatePolicy(EntityPolicy policy, bool isNew)
        {
            var validationResult = new DtoValidationResult {
                Success = true
            };

            if (string.IsNullOrEmpty(policy.Name) || !policy.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ' || c == '.'))
            {
                validationResult.Success      = false;
                validationResult.ErrorMessage = "Policy Name Is Not Valid";
                return(validationResult);
            }

            if (isNew)
            {
                if (_uow.PolicyRepository.Exists(h => h.Name == policy.Name))
                {
                    validationResult.Success      = false;
                    validationResult.ErrorMessage = "A Policy With This Name Already Exists";
                    return(validationResult);
                }
            }
            else
            {
                var originalPolicy = _uow.PolicyRepository.GetById(policy.Id);
                if (originalPolicy.Name != policy.Name)
                {
                    if (_uow.PolicyRepository.Exists(h => h.Name == policy.Name))
                    {
                        validationResult.Success      = false;
                        validationResult.ErrorMessage = "A Policy With This Name Already Exists";
                        return(validationResult);
                    }
                }
            }

            return(validationResult);
        }
Ejemplo n.º 17
0
        public string SetPolicyQuotation(ModelViewUserG objCred, ModelViewBilling obj)
        {
            var NegocioOrders = new BusinessOrder();

            var objAlerta         = new BusinessNotification();
            var NegocioUsuario    = new BusinessUsers();
            var NegocioCliente    = new BusinessClient();
            var NegocioProducto   = new BusinessProduct();
            var NegocioCotizacion = new BusinessQuotation();
            var NegocioEmpleado   = new BusinessEmployee();
            var NegocioMonitor    = new BusinessVisit();
            var NegocioPayment    = new BusinessPayment();
            var NegocioInvoice    = new BusinessInvoice();

            var dataUsuario = NegocioUsuario.GetUserByToken(objCred.TokenUser);

            if (objCred.TokenApp != GlobalConfiguration.TokenWEB)
            {
                if (objCred.TokenApp != GlobalConfiguration.TokenMobile)
                {
                    throw new Exception("TokenInvalid");
                }
            }
            if (dataUsuario == null)
            {
                throw new Exception("UserPasswordInvalid");
            }

            var    empleado   = NegocioEmpleado.GetByUserID(dataUsuario.UserID);
            var    orden      = NegocioOrders.GetByOrderID(obj.ODS);
            var    cliente    = NegocioCliente.GetByID(orden.FK_ClientID);
            var    pro        = NegocioProducto.GetByID(obj.FK_ProductID.Value);
            string Folio      = obj.Policies.Folio;
            var    cotizacion = NegocioCotizacion.GetByOrderFolio(orden.PK_OrderID, Folio);
            var    Payment    = NegocioPayment.GetPolicyPayment(orden.PK_OrderID, Folio);
            var    Invoice    = NegocioInvoice.GetPolicyInvoice(orden.PK_OrderID, Folio);
            var    LsPolicy   = GetByFolio(orden.PK_OrderID, Folio);

            SpreadsheetInfo.SetLicense("EQU2-3K5L-UZDC-SDYN");
            string         Origin = GlobalConfiguration.MabeAttachmentsLocal + "FormatoPolizas.xlsx";
            List <string>  result = obj.EMails.Split(new char[] { ';' }).ToList();
            ExcelFile      ef     = ExcelFile.Load(Origin);
            ExcelWorksheet ws     = ef.Worksheets[0];

            ws.Cells["L6"].Value = Folio;
            //ws.Cells["L7"].Value = obj.ODS;
            ws.Cells["L9"].Value  = cliente.ClientID;
            ws.Cells["L11"].Value = cliente.FirstName.ToUpper() + " " + cliente.LastName.ToUpper();
            ws.Cells["L13"].Value = pro.Model + " / " + pro.ProductName.ToUpper();
            ws.Cells["U13"].Value = DateTime.Today.ToString("dd-MM-yyyy");
            ws.Cells["L79"].Value = Folio;
            //ws.Cells["L80"].Value = obj.ODS;

            int cantidad  = 30;
            int cantidad1 = 31;

            ws.Cells["L" + cantidad1.ToString()].Value = obj.Policies.PolicyDescription;
            ws.Cells["L" + cantidad.ToString()].Value  = "Venta de Poliza";
            ws.Cells["J" + cantidad.ToString()].Value  = 1;
            ws.Cells["V" + cantidad.ToString()].Value  = Convert.ToDouble(obj.SubTotal);

            double subtotal    = Convert.ToDouble(obj.SubTotal.Substring(0));
            double iva         = Convert.ToDouble(obj.IVA.Substring(0));
            double total       = Convert.ToDouble(obj.Total.Substring(0));
            double subtotalref = subtotal;
            string totalletras = NegocioOrders.enletras(total.ToString());

            ws.Cells["M17"].Value = subtotal;
            ws.Cells["M18"].Value = iva;
            ws.Cells["U16"].Value = total;
            ws.Cells["M19"].Value = totalletras;
            string file    = "CotizaciónPoliza_" + Folio + ".pdf";
            string quotion = "CotizacionesPoliza_" + DateTime.Today.ToString("yyyyMMdd");
            string Destiny = GlobalConfiguration.MabeAttachmentsLocal + quotion + "/" + file;

            if (obj.BillingDetails.Count < 11)
            {
                ws.NamedRanges.SetPrintArea(ws.Cells.GetSubrange("J1", "W74"));
            }
            string Cotizaciones = new DirectoryInfo(GlobalConfiguration.MabeAttachmentsLocal).ToString() + quotion;

            if (!(Directory.Exists(Cotizaciones)))
            {
                Directory.CreateDirectory(Cotizaciones);
            }
            ef.Save(Destiny);
            string URL = GlobalConfiguration.urlRequest + "Content/Attachments/" + quotion + "/" + file;

            if (obj.EMails != "")
            {
                if (cotizacion == null)
                {
                    cotizacion = NegocioCotizacion.Insert(orden.PK_OrderID, subtotal.ToString(), iva.ToString(), total.ToString(), Folio, URL, obj.EstimatedTipe, empleado[0].PK_EmployeeID);
                }
                else
                {
                    cotizacion.Folio         = Folio;
                    cotizacion.IVA           = iva.ToString();
                    cotizacion.SubTotal      = subtotal.ToString();
                    cotizacion.Total         = total.ToString();
                    cotizacion.URL           = URL;
                    cotizacion.ModifyDate    = DateTime.UtcNow;
                    cotizacion.TypeQuotation = obj.EstimatedTipe;
                    cotizacion.FK_EmployeeID = empleado[0].PK_EmployeeID;
                    NegocioCotizacion.Update(cotizacion);
                }
                string sb     = File.ReadAllText(GlobalConfiguration.LocateBodyMail + "NotificationPoliza.txt");
                string lugCom = obj.ShopDate != null ? obj.ShopDate : "";
                sb = sb.Replace("#%Nombre%#", cliente.FirstName + " " + cliente.LastName);
                sb = sb.Replace("#%OrderID%#", obj.ODS);
                sb = sb.Replace("#%Folio%#", Folio);
                sb = sb.Replace("#%Modelo%#", pro.Model);
                sb = sb.Replace("#%Descripcion%#", pro.ProductName.ToUpper());
                sb = sb.Replace("#%Fecha%#", obj.Policies.PolicyDate);
                sb = sb.Replace("#%Vigencia1%#", obj.Policies.PolicyDescription);
                sb = sb.Replace("#%Precio%#", obj.Total);
                objAlerta.SendMailExchange(GlobalConfiguration.exchangeUserCotiza, GlobalConfiguration.exchangePwdCotiza, result, "Cotización ServiPlus", sb.ToString(), Destiny);
            }
            else
            {
                if (LsPolicy.PK_PolicyID == 0)
                {
                    if (cotizacion == null)
                    {
                        cotizacion = NegocioCotizacion.Insert(orden.PK_OrderID, subtotal.ToString(), iva.ToString(), total.ToString(), Folio, URL, obj.EstimatedTipe, empleado[0].PK_EmployeeID);
                    }
                    else
                    {
                        cotizacion.Folio         = Folio;
                        cotizacion.IVA           = iva.ToString();
                        cotizacion.SubTotal      = subtotal.ToString();
                        cotizacion.Total         = total.ToString();
                        cotizacion.URL           = URL;
                        cotizacion.ModifyDate    = DateTime.UtcNow;
                        cotizacion.TypeQuotation = obj.EstimatedTipe;
                        cotizacion.FK_EmployeeID = empleado[0].PK_EmployeeID;
                        NegocioCotizacion.Update(cotizacion);
                    }
                    var NewPolicy   = new EntityPolicy();
                    var NuevaPoliza = new EntityPolicy();

                    NewPolicy.FK_OrderID     = orden.PK_OrderID;
                    NewPolicy.FK_ClientID    = cliente.PK_ClientID;
                    NewPolicy.FK_EmployeeID  = empleado[0].PK_EmployeeID;
                    NewPolicy.FK_PaymentID   = Payment.PK_PaymentID;
                    NewPolicy.FK_Invoice_ID  = Invoice.InvoicingID;
                    NewPolicy.FK_QuotationID = cotizacion.PK_QuotationID;
                    NewPolicy.FK_ProductID   = pro.PK_ProductID;
                    NewPolicy.FK_ShopPlace   = obj.FK_ShopPlaceID.Value;
                    NewPolicy.IDPolicy       = obj.Policies.Folio;
                    NewPolicy.SerialNumber   = obj.SerialNumber;
                    NewPolicy.PriceList      = obj.Policies.PriceList;
                    NewPolicy.PolicyPrice    = obj.Policies.PolicyPrice;
                    NewPolicy.Coin           = obj.Policies.Coin;
                    NewPolicy.SalesOrg       = obj.Policies.SalesOrg;
                    NewPolicy.ccGroup        = obj.Policies.ccGroup;
                    NewPolicy.MaterialGroup4 = obj.Policies.MaterialGroup4;
                    NewPolicy.GuarantyStart  = Convert.ToDateTime(obj.Policies.GuarantyStart);
                    NewPolicy.GuarantyEnd    = Convert.ToDateTime(obj.Policies.GuarantyEnd);
                    NewPolicy.PolicyDate     = obj.Policies.PolicyDate;

                    NuevaPoliza = Insert(NewPolicy);
                }
                else
                {
                    LsPolicy.FK_OrderID     = orden.PK_OrderID;
                    LsPolicy.FK_ClientID    = cliente.PK_ClientID;
                    LsPolicy.FK_EmployeeID  = empleado[0].PK_EmployeeID;
                    LsPolicy.FK_PaymentID   = Payment.PK_PaymentID;
                    LsPolicy.FK_Invoice_ID  = Invoice.InvoicingID;
                    LsPolicy.FK_QuotationID = LsPolicy.FK_QuotationID;
                    LsPolicy.FK_ProductID   = obj.Policies.ProductID;
                    LsPolicy.FK_ShopPlace   = obj.FK_ShopPlaceID.Value;
                    LsPolicy.IDPolicy       = obj.Policies.Folio;
                    LsPolicy.PolicyPrice    = obj.Policies.PolicyPrice;
                    LsPolicy.Coin           = obj.Policies.Coin;
                    LsPolicy.SalesOrg       = obj.Policies.SalesOrg;
                    LsPolicy.PriceList      = obj.Policies.PriceList;
                    LsPolicy.SerialNumber   = obj.SerialNumber;
                    LsPolicy.ccGroup        = obj.Policies.ccGroup;
                    LsPolicy.MaterialGroup4 = obj.Policies.MaterialGroup4;
                    LsPolicy.GuarantyEnd    = Convert.ToDateTime(obj.Policies.GuarantyEnd);
                    LsPolicy.GuarantyStart  = Convert.ToDateTime(obj.Policies.GuarantyStart);
                    LsPolicy.PolicyDate     = obj.Policies.PolicyDate;

                    Update(LsPolicy);
                    if (cotizacion == null)
                    {
                        cotizacion = NegocioCotizacion.Insert(orden.PK_OrderID, subtotal.ToString(), iva.ToString(), total.ToString(), Folio, URL, obj.EstimatedTipe, empleado[0].PK_EmployeeID);
                    }
                    else
                    {
                        cotizacion.Folio         = Folio;
                        cotizacion.IVA           = iva.ToString();
                        cotizacion.SubTotal      = subtotal.ToString();
                        cotizacion.Total         = total.ToString();
                        cotizacion.URL           = URL;
                        cotizacion.ModifyDate    = DateTime.UtcNow;
                        cotizacion.TypeQuotation = obj.EstimatedTipe;
                        cotizacion.FK_EmployeeID = empleado[0].PK_EmployeeID;
                        NegocioCotizacion.Update(cotizacion);
                    }
                }
                var Refacciones = new BusinessMabe().Orden_Venta(obj.ODS, obj.ServiceTypes, Folio);
            }



            return(obj.ODS);
        }
        public void TestCustomersIncludeThenAssociateOrders()
        {
            var policy = new EntityPolicy();
            policy.IncludeWith<Customer>(c => c.Orders);
            policy.AssociateWith<Customer>(c => c.Orders.Where(o => (o.OrderID & 1) == 0));
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI").ToList();
            AssertValue(1, custs.Count);
            AssertNotValue(null, custs[0].Orders);
            AssertValue(3, custs[0].Orders.Count);
        }
Ejemplo n.º 19
0
        protected void btnAdd_OnClick(object sender, EventArgs e)
        {
            var policy = new EntityPolicy();

            policy.Name        = txtName.Text;
            policy.Description = txtDescription.Text;
            policy.Trigger     =
                (EnumPolicy.Trigger)Enum.Parse(typeof(EnumPolicy.Trigger), ddlTrigger.SelectedValue);
            policy.Frequency = (EnumPolicy.Frequency)Enum.Parse(typeof(EnumPolicy.Frequency), ddlFrequency.SelectedValue);
            if (policy.Frequency == EnumPolicy.Frequency.OncePerWeek)
            {
                policy.SubFrequency = Convert.ToInt16((EnumCalendar.DayOfWeek)Enum.Parse(typeof(EnumCalendar.DayOfWeek), ddlWeekDay.SelectedValue));
            }
            else if (policy.Frequency == EnumPolicy.Frequency.OncePerMonth)
            {
                policy.SubFrequency = Convert.ToInt16(ddlMonthDay.SelectedValue);
            }
            else if (policy.Frequency == EnumPolicy.Frequency.EveryXdays)
            {
                policy.SubFrequency = Convert.ToInt16(txtDays.Text);
            }
            else if (policy.Frequency == EnumPolicy.Frequency.EveryXhours)
            {
                policy.SubFrequency = Convert.ToInt16(txtHours.Text);
            }
            else
            {
                policy.SubFrequency = 0;
            }

            policy.WindowStartScheduleId = Convert.ToInt32(ddlScheduleStart.SelectedValue);
            policy.WindowEndScheduleId   = Convert.ToInt32(ddlScheduleEnd.SelectedValue);
            policy.ConditionId           = Convert.ToInt32(ddlCondition.SelectedValue);
            policy.ConditionFailedAction = (EnumCondition.FailedAction)Enum.Parse(typeof(EnumCondition.FailedAction), ddlConditionFailedAction.SelectedValue);
            //utc is not used here because time is not used only date
            policy.StartDate             = string.IsNullOrEmpty(txtStartDate.Text) ? Convert.ToDateTime(DateTime.Now.ToShortDateString()) : Convert.ToDateTime(txtStartDate.Text);
            policy.CompletedAction       = (EnumPolicy.CompletedAction)Enum.Parse(typeof(EnumPolicy.CompletedAction), ddlCompletedAction.SelectedValue);
            policy.RunInventory          = (EnumPolicy.InventoryAction)Enum.Parse(typeof(EnumPolicy.InventoryAction), ddlInventory.SelectedValue);
            policy.RunLoginTracker       = chkLoginTracker.Checked;
            policy.RemoveInstallCache    = chkDeleteCache.Checked;
            policy.MissedAction          = (EnumPolicy.FrequencyMissedAction)Enum.Parse(typeof(EnumPolicy.FrequencyMissedAction), ddlMissed.SelectedValue);
            policy.ExecutionType         = (EnumPolicy.ExecutionType)Enum.Parse(typeof(EnumPolicy.ExecutionType), ddlExecType.SelectedValue);
            policy.ErrorAction           = (EnumPolicy.ErrorAction)Enum.Parse(typeof(EnumPolicy.ErrorAction), ddlErrorAction.SelectedValue);
            policy.LogLevel              = (EnumPolicy.LogLevel)Enum.Parse(typeof(EnumPolicy.LogLevel), ddlLogLevel.SelectedValue);
            policy.WuType                = (EnumPolicy.WuType)Enum.Parse(typeof(EnumPolicy.WuType), ddlWinUpdates.SelectedValue);
            policy.SkipServerResult      = chkSkipResult.Checked;
            policy.RunApplicationMonitor = chkApplicationMonitor.Checked;
            policy.AutoArchiveType       = (EnumPolicy.AutoArchiveType)Enum.Parse(typeof(EnumPolicy.AutoArchiveType), ddlAutoArchive.SelectedValue);
            policy.PolicyComCondition    = (EnumPolicy.PolicyComCondition)Enum.Parse(typeof(EnumPolicy.PolicyComCondition), ddlComCondition.SelectedValue);
            if (policy.AutoArchiveType == EnumPolicy.AutoArchiveType.AfterXdays)
            {
                policy.AutoArchiveSub = txtAutoArchiveDays.Text;
            }


            var result = Call.PolicyApi.Post(policy);

            if (!result.Success)
            {
                EndUserMessage = result.ErrorMessage;
            }
            else
            {
                if (policy.PolicyComCondition != EnumPolicy.PolicyComCondition.Any)
                {
                    var list = new List <EntityPolicyComServer>();
                    foreach (GridViewRow row in gvServers.Rows)
                    {
                        var cb = (CheckBox)row.FindControl("chkSelector");
                        if (cb == null || !cb.Checked)
                        {
                            continue;
                        }
                        var dataKey = gvServers.DataKeys[row.RowIndex];
                        if (dataKey == null)
                        {
                            continue;
                        }
                        var policyComServer = new EntityPolicyComServer();
                        policyComServer.ComServerId = Convert.ToInt32(dataKey.Value);
                        policyComServer.PolicyId    = result.Id;

                        list.Add(policyComServer);
                    }

                    var z = Call.PolicyComServerApi.Post(list);
                    if (!z.Success)
                    {
                        EndUserMessage = z.ErrorMessage;
                        return;
                    }
                }

                EndUserMessage = "Successfully Created Policy";
                Response.Redirect("~/views/policies/general.aspx?policyId=" + result.Id);
            }
        }
		public QueryTranslator(QueryMapping mapping, EntityPolicy policy)
		{
			this.Mapper = mapping.CreateMapper(this);
			this.Police = policy.CreatePolice(this);
		}
        public void TestCustomersIncludeOrdersViaConstructorOnly()
        {
            var mapping = new AttributeMapping(typeof(NorthwindX));
            var policy = new EntityPolicy();
            policy.IncludeWith<CustomerX>(c => c.Orders);
            NorthwindX nw = new NorthwindX(this.provider.New(policy).New(mapping));

            var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI").ToList();
            AssertValue(1, custs.Count);
            AssertNotValue(null, custs[0].Orders);
            AssertValue(6, custs[0].Orders.Count);
        }
        public void TestCustomersAssociateOrders()
        {
            var policy = new EntityPolicy();
            policy.AssociateWith<Customer>(c => c.Orders.Where(o => (o.OrderID & 1) == 0));
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI")
                .Select(c => new { CustomerID = c.CustomerID, FilteredOrdersCount = c.Orders.Count() }).ToList();
            AssertValue(1, custs.Count);
            AssertValue(3, custs[0].FilteredOrdersCount);
        }
Ejemplo n.º 23
0
 public EntityPolicy Update(EntityPolicy data)
 {
     return(new RepositoryPolicy().Update(data));
 }
Ejemplo n.º 24
0
        public void TestCustomersIncludeOrdersWhere()
        {
            var policy = new EntityPolicy();
            policy.IncludeWith<Customer>(c => c.Orders.Where(o => (o.OrderID & 1) == 0));
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI").ToList();
            Assert.AreEqual(1, custs.Count);
            Assert.IsNotNull(custs[0].Orders);
            Assert.AreEqual(3, custs[0].Orders.Count);
        }
Ejemplo n.º 25
0
        public DtoActionResult Validate(int policyId)
        {
            _policy = _policyService.GetPolicy(policyId);
            if (_policy == null)
            {
                _result.Success      = false;
                _result.ErrorMessage = "Could Not Find A Policy With Id: " + policyId;
                return(_result);
            }

            string verifyResult;

            verifyResult = VerifyPolicy();
            if (verifyResult != null)
            {
                _result.Success      = false;
                _result.ErrorMessage = verifyResult;
                return(_result);
            }

            var policyModules = _policyService.SearchAssignedPolicyModules(policyId, _filter);

            foreach (var policyModule in policyModules.OrderBy(x => x.Name))
            {
                verifyResult = VerifyConditions(policyModule, policyModules);
                if (verifyResult != null)
                {
                    _result.Success      = false;
                    _result.ErrorMessage = verifyResult;
                    return(_result);
                }

                if (policyModule.ModuleType == EnumModule.ModuleType.Command)
                {
                    verifyResult = VerifyCommand(policyModule);
                    if (verifyResult != null)
                    {
                        _result.Success      = false;
                        _result.ErrorMessage = verifyResult;
                        return(_result);
                    }
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.FileCopy)
                {
                    verifyResult = VerifyFileCopy(policyModule);
                    if (verifyResult != null)
                    {
                        _result.Success      = false;
                        _result.ErrorMessage = verifyResult;
                        return(_result);
                    }
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Message)
                {
                    verifyResult = VerifyMessage(policyModule);
                    if (verifyResult != null)
                    {
                        _result.Success      = false;
                        _result.ErrorMessage = verifyResult;
                        return(_result);
                    }
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Script)
                {
                    verifyResult = VerifyScript(policyModule);
                    if (verifyResult != null)
                    {
                        _result.Success      = false;
                        _result.ErrorMessage = verifyResult;
                        return(_result);
                    }
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Printer)
                {
                    verifyResult = VerifyPrinter(policyModule);
                    if (verifyResult != null)
                    {
                        _result.Success      = false;
                        _result.ErrorMessage = verifyResult;
                        return(_result);
                    }
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Software)
                {
                    verifyResult = VerifySoftware(policyModule);
                    if (verifyResult != null)
                    {
                        _result.Success      = false;
                        _result.ErrorMessage = verifyResult;
                        return(_result);
                    }
                }
                else if (policyModule.ModuleType == EnumModule.ModuleType.Wupdate)
                {
                    verifyResult = VerifyWindowsUpdate(policyModule);
                    if (verifyResult != null)
                    {
                        _result.Success      = false;
                        _result.ErrorMessage = verifyResult;
                        return(_result);
                    }
                }
            }

            _result.Success = true;
            return(_result);
        }
        public void TestCustomersApplyComputedFilter()
        {
            string ci = "Lon";
            string ty = "don";
            var policy = new EntityPolicy();
            policy.Apply<Customer>(seq => seq.Where(c => c.City == ci + ty));
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.ToList();
            AssertValue(6, custs.Count);
        }
		private RelationshipIncluder(QueryMapper mapper)
		{
			this.mapper = mapper;
			this.policy = mapper.Translator.Police.Policy;
		}
        public void TestOrdersIncludeDetailsWithFirst()
        {
            EntityPolicy policy = new EntityPolicy();
            policy.IncludeWith<Order>(o => o.Details);

            var ndb = new Northwind(provider.New(policy));
            var q = from o in ndb.Orders
                    where o.OrderID == 10248
                    select o;

            Order so = q.Single();
            AssertValue(3, so.Details.Count);
            Order fo = q.First();
            AssertValue(3, fo.Details.Count);
        }
		private ClientJoinedProjectionRewriter(EntityPolicy policy)
		{
			this.policy = policy;
		}
        public void TestCustomersIncludeOrdersAndDetails()
        {
            var policy = new EntityPolicy();
            policy.IncludeWith<Customer>(c => c.Orders);
            policy.IncludeWith<Order>(o => o.Details);
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI").ToList();
            AssertValue(1, custs.Count);
            AssertNotValue(null, custs[0].Orders);
            AssertValue(6, custs[0].Orders.Count);
            AssertTrue(custs[0].Orders.Any(o => o.OrderID == 10643));
            AssertNotValue(null, custs[0].Orders.Single(o => o.OrderID == 10643).Details);
            AssertValue(3, custs[0].Orders.Single(o => o.OrderID == 10643).Details.Count);
        }
		public static Expression Rewrite(EntityPolicy policy, Expression expression)
		{
			return new ClientJoinedProjectionRewriter(policy).Visit(expression);
		}
        public void TestCustomersIncludeOrdersDeferred()
        {
            var policy = new EntityPolicy();
            policy.IncludeWith<Customer>(c => c.Orders, true);
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI").ToList();
            AssertValue(1, custs.Count);
            AssertNotValue(null, custs[0].Orders);
            AssertValue(6, custs[0].Orders.Count);
        }
        public void TestCustomersApplyFilterTwice()
        {
            var policy = new EntityPolicy();
            policy.Apply<Customer>(seq => seq.Where(c => c.City == "London"));
            policy.Apply<Customer>(seq => seq.Where(c => c.Country == "UK"));
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.ToList();
            AssertValue(6, custs.Count);
        }
Ejemplo n.º 34
0
        public void TestInsertCustomersIncludeOrders()
        {
            var policy = new EntityPolicy();
            policy.IncludeWith<Customer>(c => c.Orders);
            policy.IncludeWith<Order>(o => o.Details);
            Northwind nw = new Northwind(this.provider.New(policy));

            var cust = new Customer
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA"
            };
            var order = new Order
            {
                CustomerID = "XX1",
                OrderDate = DateTime.Today,
            };
            cust.Orders = new List<Order> { order };

            var custs = nw.Customers.Insert(cust);
            var result = nw.Orders.Insert(order);
            cust = nw.Customers.GetById(cust.CustomerID);
            Assert.AreEqual(1, custs);
            //TODO: Complete Assert
            //Assert.IsNotNull(custs[0].Orders);
            //Assert.AreEqual(6, custs[0].Orders.Count);
            //Assert.IsTrue(custs[0].Orders.Any(o => o.OrderID == 10643));
            //Assert.IsNotNull(custs[0].Orders.Single(o => o.OrderID == 10643).Details);
            //Assert.AreEqual(3, custs[0].Orders.Single(o => o.OrderID == 10643).Details.Count);
        }
 public void TestOrdersIncludeDetailsWithGroupBy()
 {
     var policy = new EntityPolicy();
     policy.IncludeWith<Order>(o => o.Details);
     Northwind nw = new Northwind(this.provider.New(policy));
     var list = nw.Orders.Where(o => o.CustomerID == "ALFKI").GroupBy(o => o.CustomerID).ToList();
     AssertValue(1, list.Count);
     var grp = list[0].ToList();
     AssertValue(6, grp.Count);
     var o10643 = grp.SingleOrDefault(o => o.OrderID == 10643);
     AssertNotValue(null, o10643);
     AssertValue(3, o10643.Details.Count);
 }
        public void TestCustomersApplyOrder()
        {
            var policy = new EntityPolicy();
            policy.Apply<Customer>(seq => seq.OrderBy(c => c.ContactName));
            Northwind nw = new Northwind(this.provider.New(policy));

            var list = nw.Customers.Where(c => c.City == "London").ToList();

            AssertValue(6, list.Count);
            var sorted = list.OrderBy(c => c.ContactName).ToList();
            AssertTrue(Enumerable.SequenceEqual(list, sorted));
        }