Ejemplo n.º 1
0
        public void AddLocalPatch(int id, string url, int version)
        {
            LocalPatch patch = LocalPatch.CreateLocalPatch(id, url, version);

            _context.AddToLocalPatchContext(patch);
            _context.SaveChanges();
        }
        public IActionResult Patch([FromBody] LocalPatch ltemp)
        {
            if (ltemp.Id >= 0)
            {
                try {
                    var local = database.Local.First(p => p.Id == ltemp.Id);
                    //Editar
                    if (ltemp.Nome != null)
                    {
                        if (ltemp.Nome.Length > 0 && ltemp.Nome.Length < 100)
                        {
                            local.Nome = ltemp.Nome;
                        }
                        else
                        {
                            Response.StatusCode = 404;
                            return(new ObjectResult(new { msg = "Nome  inválido" }));
                        }
                    }

                    if (ltemp.Endereco != null)
                    {
                        if (ltemp.Endereco.Length > 0 && ltemp.Endereco.Length < 100)
                        {
                            local.Endereco = ltemp.Endereco;
                        }
                        else
                        {
                            Response.StatusCode = 404;
                            return(new ObjectResult(new { msg = "Endereço  inválido" }));
                        }
                    }
                    if (ltemp.LinkEndereco != null)
                    {
                        if (ltemp.LinkEndereco.Length > 0 && ltemp.LinkEndereco.Length < 1024)
                        {
                            local.LinkEndereco = ltemp.LinkEndereco;
                        }
                        else
                        {
                            Response.StatusCode = 404;
                            return(new ObjectResult(new { msg = "Url  inválida" }));
                        }
                    }
                    database.SaveChanges();
                    return(Ok(new { msg = "Local Atualilzado!" }));
                } catch (System.Exception) {
                    Response.StatusCode = 404;
                    return(new ObjectResult(new { msg = "Requisição Inválida!" }));
                }
            }
            else
            {
                Response.StatusCode = 404;
                return(new ObjectResult(new { msg = "ID inválido" }));
            }
        }
 public void AddToLocalPatchContext(LocalPatch localPatch)
 {
     base.AddObject("LocalPatchContext", localPatch);
 }
 public static LocalPatch CreateLocalPatch(long shardId, string patchUrl, long version)
 {
     LocalPatch localPatch = new LocalPatch();
     localPatch.ShardId = shardId;
     localPatch.PatchUrl = patchUrl;
     localPatch.Version = version;
     return localPatch;
 }