Beispiel #1
0
        public async Task <Int32> CreateAsync(Models.Policy newPolicy)
        {
            Entities.Policy model = newPolicy.ToEntity();

            _context.Policies.Add(model);

            await _context.SaveChangesAsync();

            return(model.Id);
        }
Beispiel #2
0
 public Result applyRule(Models.Policy policy)
 {
     // Check that policy has at least one driver
     if (policy.Drivers != null && policy.Drivers.Count > 0)
     {
         return(new Result(true, ""));
     }
     else
     {
         return(new Result(false, "Policy must have at least one driver"));
     }
 }
Beispiel #3
0
        public async Task <Models.Policy> GetAsync(Int32 policyId)
        {
            Entities.Policy policy = await _context.Policies
                                     .AsNoTracking()
                                     .FirstOrDefaultAsync(p => p.Id == policyId);

            Models.Policy model = policy?.ToModel();

            _logger.LogDebug($"{policyId} found in database: {model != null}");

            return(model);
        }
Beispiel #4
0
        public async Task <ActionResult <Policy> > SavePolicy([FromBody] DTO_Policy _Policyp)
        {
            Policy _Policy = _Policyp;

            try
            {
                // DTO_NumeracionSAR _liNumeracionSAR = new DTO_NumeracionSAR();
                string     baseadress = config.Value.urlbase;
                HttpClient _client    = new HttpClient();
                _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                var result = await _client.GetAsync(baseadress + "api/Policies/GetPoliciesById/" + _Policy.Id);

                string valorrespuesta = "";
                _Policy.FechaModificacion   = DateTime.Now;
                _Policy.UsuarioModificacion = HttpContext.Session.GetString("user");
                if (result.IsSuccessStatusCode)
                {
                    valorrespuesta = await(result.Content.ReadAsStringAsync());
                    _Policy        = JsonConvert.DeserializeObject <Policy>(valorrespuesta);
                }

                if (_Policy == null)
                {
                    _Policy = new Models.Policy();
                }
                //_Policy.Id.ToString("N");
                // _Policy = _Policy.Where(q => q.Id == Id).ToList();


                if (_Policyp.Id.ToString() == "00000000-0000-0000-0000-000000000000")

                {
                    _Policy.FechaCreacion   = DateTime.Now;
                    _Policy.UsuarioCreacion = HttpContext.Session.GetString("user");
                    var insertresult = await Insert(_Policyp);
                }
                else
                {
                    _Policyp.UsuarioCreacion = _Policy.UsuarioCreacion;
                    _Policyp.FechaCreacion   = _Policy.FechaCreacion;
                    var updateresult = await Update(_Policyp.Id, _Policyp);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                throw ex;
            }

            return(Json(_Policy));
        }
Beispiel #5
0
        public async Task UpdateAsync(Int32 policyId, Models.Policy policy)
        {
            if (policyId != policy.Id)
            {
                throw new ArgumentException(nameof(policyId));
            }

            Entities.Policy model = await _context.Policies.SingleOrDefaultAsync(p => p.Id == policyId);

            model         = policy.ToEntity(model);
            model.Updated = DateTime.UtcNow;

            await _context.SaveChangesAsync();
        }
 public static Entities.Policy ToEntity(this Models.Policy model, Entities.Policy entity)
 {
     return(Mapper.Map(model, entity));
 }
 public static Entities.Policy ToEntity(this Models.Policy model)
 {
     return(Mapper.Map <Entities.Policy>(model));
 }