Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Classification,Ordinal")] RiskClass riskClass)
        {
            if (id != riskClass.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(riskClass);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RiskClassExists(riskClass.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(riskClass));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,Classification,Ordinal")] RiskClass riskClass)
        {
            if (ModelState.IsValid)
            {
                _context.Add(riskClass);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(riskClass));
        }
Beispiel #3
0
        /// <summary>
        /// Creates a risk identifier from imported data, if possible.
        /// </summary>
        /// <param name="riskClass"></param>
        /// <returns></returns>
        public string CreateRiskIdentifier(RiskClass riskClass)
        {
            var riskIdentifiers = riskClass.Identifiers;
            var parts           = new List <string>();

            foreach (var identifier in riskIdentifiers)
            {
                var entityName = identifier.GetAttributeValue <AliasedValue>("new_fieldmapping.new_destinationentityschemaname").ToValue <string>();
                var fieldName  = identifier.GetAttributeValue <AliasedValue>("new_fieldmapping.new_destinationfield").ToValue <string>();

                if (string.IsNullOrEmpty(entityName) || string.IsNullOrEmpty(fieldName))
                {
                    continue;
                }

                // special handling of new_address.new_name
                if (fieldName == "new_address")
                {
                    var insuredRiskAddressAttrs = _attrs
                                                  .ForEntity("new_address")
                                                  .ForAddressOf(AddressOf.InsuredRisk);

                    var addressName = StringifyAddress(insuredRiskAddressAttrs, _defaults.Country);
                    parts.Add(addressName);
                }
                else
                {
                    var identifierAttr = _attrs
                                         .ForEntity(entityName)
                                         .ForAttribute(fieldName)
                                         .FirstOrDefault();

                    if (identifierAttr == null)
                    {
                        continue;
                    }

                    parts.Add(identifierAttr.Value);
                }
            }

            if (parts.Any())
            {
                return(string.Join(" - ", parts));
            }
            else
            {
                return(null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Ensures that risk entity (e.g. Vehicle) exists in CRM. Based on Risk Class identifiers, checks if
        /// risk entity exists in CRM. If so, returns existing entity. Otherwise, creates new risk entity
        /// based on attributes.
        /// </summary>
        /// <param name="riskClass"></param>
        /// <returns></returns>
        public Entity ImportRiskEntity(RiskClass riskClass)
        {
            var riskEntityName  = riskClass.RiskEntity;
            var riskEntityAttrs = _attrs.ForEntity(riskEntityName);

            var currentRowIdentifier = CreateRiskIdentifier(riskClass);

            if (currentRowIdentifier != null)
            {
                var existingRisks = _svc.RetrieveMultipleByName(riskEntityName, currentRowIdentifier);

                if (existingRisks.Any())
                {
                    return(existingRisks.FirstOrDefault());
                }
            }

            var risk = new Entity(riskEntityName);

            risk.UpdateWithAttributes(riskEntityAttrs);

            risk.Id = _svc.Create(risk);
            return(risk);
        }
Beispiel #5
0
        protected void SetIdentifier(LocalPluginContext context)
        {
            var    target   = context.PluginExecutionContext.InputParameters["Target"] as Entity;
            Entity preImage = null;

            if (context.PluginExecutionContext.MessageName == "Update")
            {
                preImage = context.PreImage;
            }

            // name was explicitly set by another code/plug-in, keep it as it is
            if (target.Contains("new_name"))
            {
                return;
            }

            // get risk class for a name of entity, for which is this plug-in currently firing
            var riskClassEntity = RiskClass.RetrieveForEntityName(context.OrganizationService, target.LogicalName);

            // if no risk class is defined do not generate name
            if (riskClassEntity == null)
            {
                return;
            }

            var riskClass       = new RiskClass(context.OrganizationService, context.TracingService, riskClassEntity);
            var riskIdentifiers = riskClass.Identifiers;

            var identifier = GetRiskIdentifierString(context.OrganizationService, null, null, target, riskIdentifiers);

            // previous call returns null if if fails to create a name
            if (identifier != null)
            {
                target["new_name"] = identifier;
            }
        }