示例#1
0
        public async Task <Cif> Process(Cif cif)
        {
            if (CifValidator.Validate(cif.Name) == true)
            {
                cif.IsCached = false;
                cif.DataApel = DateTime.Now.ToString("yyyy-MM-dd");
                cif.IsValid  = true;
                string _name = cif.Name;

                var query = await _context.Cifs.Where(s => s.DataApel == cif.DataApel && s.Name == cif.Name).FirstOrDefaultAsync();

                if (query == null)
                {
                    if (cif.Name.StartsWith("RO"))
                    {
                        _name = cif.Name.Substring(2);
                    }
                    if (!CheckAnaf())
                    {
                        return(null);
                    }

                    string rez = AnafReq.SendReq(_name);


                    var t = new JObject();
                    t = JObject.Parse(rez);


                    if (!t.SelectToken("$.cod").ToString().Equals("200"))
                    {
                        return(null);
                    }

                    cif.Denumire          = t.SelectToken("found[0].denumire").ToString();
                    cif.Adresa            = t.SelectToken("found[0].adresa").ToString();
                    cif.PlatitorTVA       = bool.Parse(t.SelectToken("found[0].scpTVA").ToString());
                    cif.StatusTVAIncasare = bool.Parse(t.SelectToken("found[0].statusTvaIncasare").ToString());
                    cif.StatusActiv       = bool.Parse(t.SelectToken("found[0].statusInactivi").ToString());
                    cif.IsCached          = true;
                    _context.Cifs.Add(cif);
                    await _context.SaveChangesAsync();

                    cif.IsCached = false;
                    return(cif);
                }

                return(query);
            }


            return(null);
        }
        public async Task <ActionResult <Cif> > PostCif(Cif cif)
        {
            if (!_processReq.CheckDatabase())
            {
                return(BadRequest("SQL Server Offline"));
            }

            if (!_processReq.CheckAnaf())
            {
                return(BadRequest("ANAF Service Offline"));
            }

            var c = await _processReq.Process(cif);

            if (c == null)
            {
                return(BadRequest("Cif Invalid"));
            }



            return(CreatedAtAction(nameof(GetCif), new { id = cif.Id }, c));
        }
示例#3
0
 /// <summary>  </summary>
 /// <returns></returns>
 public bool IsValid()
 {
     return(Nif.Create(Value).IsValid() || Cif.Create(Value).IsValid());
 }
示例#4
0
 public void CifKos(string value)
 {
     Cif.Create(value).IsValid().Should().BeFalse();
 }
示例#5
0
 public void CifOks(string value)
 {
     Cif.Create(value).IsValid().Should().BeTrue();
 }